以下是我的代码,我在调用函数时遇到了一些错误,但我无法找到它,请帮助我。
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);
},
答案 0 :(得分:4)
在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`