以下是我的代码,在某个地方我在调用该函数时做错了什么,但我找不到它,请为此提供帮助。
this._copyChild(final_features);
上面的代码行在下面的程序中给了我以上错误,请参见代码中的箭头
launch: function() {
Ext.create('Rally.ui.dialog.ChooserDialog', {
width: 450,
autoScroll: true,
height: 525,
title: 'Select to Copy',
pageSize: 100,
closable: false,
selectionButtonText: 'Copy',
artifactTypes: ['PortfolioItem/Feature','PortfolioItem/MMF'],
autoShow: true,
storeConfig:{
fetch: ['Name','PortfolioItemTypeName']
},
listeners: {
artifactChosen: function(selectedRecord) {
childrens = [];
this._type = selectedRecord.get('PortfolioItemTypeName');
this._newObj = selectedRecord;
this.onqModelRetrieved();
this.getChildrens(selectedRecord);
},
scope: this
},
});
},
getChildrens: function(selectedRecord) {
Ext.create('Rally.data.wsapi.Store', {
model: 'PortfolioItem/' + this._newObj.get('PortfolioItemTypeName'),
fetch: ['Name', 'FormattedID', 'Children'],
pageSize: 1,
autoLoad: true,
listeners: {
load: function(store, records) {
final_features = [];
Ext.Array.each(records, function(child){
var item = selectedRecord;
var childrens = item.getCollection('Children');
childrens.load({
fetch: ['FormattedID'],
callback: function(childrens, operation, success){
Ext.Array.each(childrens, function(child){
if (child.get('PortfolioItemTypeName') == "Feature") {
final_features.push(child);
=============> this._copyChild(final_features);
}
}, this);
},
scope: this
});
}, this);
}
}
});
},
// Inner Copy functions
_copyChild: function(final_features) {
var that = child;
this.innerModelRetrieved(child);
},
在该each
函数内部,this
不是指向外部对象,而是指向该listeners
对象。
在getChildrens
函数的开头创建一个指向外部对象的局部变量,并用它替换所有作用域参数。
getChildrens: function(selectedRecord) {
var self = this; // <-- local copy of `this` (owner of getChildrens)
Ext.create('Rally.data.wsapi.Store', {
...
Ext.Array.each(childrens, function(child){
if (child.get('PortfolioItemTypeName') == "Feature") {
final_features.push(child);
this._copyChild(final_features);
}
}, self); // <--- replace `this` with `self`
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句