【发布时间】:2014-09-22 06:12:52
【问题描述】:
在下面的代码中,在控制台 4 上的 _copyChild 和 innerModelRetrieved 函数中逐一打印功能,但在下一个功能 onInnerModelRetrieved 4 次打印最后一个功能值时,我无法弄清楚为什么会这样。请帮我解决这个问题。
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
_newObj : {},
childrens: [],
_type : null,
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','PortfolioItem/Epic', 'PortfolioItem/Program'],
autoShow: true,
storeConfig:{
fetch: ['Name','PortfolioItemTypeName']
},
listeners: {
artifactChosen: function(selectedRecord) {
childrens = [];
this._type = selectedRecord.get('PortfolioItemTypeName');
this._newObj = selectedRecord;
this.onqModelRetrieved();
var self = this;
Ext.create('Rally.data.wsapi.Store', {
model: 'PortfolioItem/' + selectedRecord.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;
childrens = item.getCollection('Children');
childrens.load({
fetch: ['FormattedID'],
callback: function(records, operation, success){
Ext.Array.each(records, function(portfolioitem){
if (portfolioitem.get('PortfolioItemTypeName') == "Feature") {
self._childObj = portfolioitem;
self._copyChild();
}
}, self);
},
scope: this
});
}, self);
}
}
});
},
scope: this
},
});
},
// Inner Copy functions
_copyChild: function() {
console.log("child value here", that._childObj);
this.innerModelRetrieved();
},
innerModelRetrieved: function() {
var that = this
console.log("next child value here", that._childObj);
that._type = 'PortfolioItem/' + that._childObj.get('PortfolioItemTypeName');
Rally.data.ModelFactory.getModel({
type: that._type,
success: that.onInnerModelRetrieved,
scope: that
});
},
onInnerModelRetrieved: function(model) {
console.log("next child value here", this._childObj);
this.model = model;
this.genericInnerCopy(model);
},
【问题讨论】:
-
你应该清理你的代码并发布一个可以正确格式化的例子。就目前而言,它是一团乱麻。
-
@existdissolve - 对不起..我会编辑并再次发布。
-
@existdissolve - 我认为现在代码更具可读性。你能理解它吗?
标签: javascript extjs extjs4 rally