在我的應用程序,當我試圖複製一個對象它的複製,但如果我定義另一個函數調用,正確執行的代碼會給出錯誤,不知道爲什麼。任何幫助的高度讚賞,並感謝提前評論一個功能代碼的作品,否則它失敗
如果我評論此功能that._createCustomStore(data);
一切工作不錯,如果我取消這一點,讓我錯誤爲Uncaught ReferenceError: _newParent is not defined
在這條線copiedParent = _newParent;
是我的代碼
_genericInnerCopy: function(_childObj) {
copiedParent = {};
that = this;
model = that.model;
var record = Ext.create(model, {
Name: _childObj.get('Name'),
//Parent: _newParent.get("_ref");,
});
record.save({
callback: function(result, operation) {
if(operation.wasSuccessful()) {
console.log("Done");
//that._copyChild();
} else {
console.log("error");
}
}
})
that._all_pis.push(record);
copiedParent = _newParent;
var store = Ext.create('Rally.data.custom.Store', {
data: that._all_pis,
listeners: {
load: function(store,data,success) {
that._updateAll(store, data, copiedParent);
},
scope: that
},
});
//console.log("record values", that._all_pis);
},
_updateAll: function(store,data, copiedParent) {
that = this;
Rally.data.BulkRecordUpdater.updateRecords({
records: data,
propertiesToUpdate: {
Parent: copiedParent.get("_ref")
},
success: function(readOnlyRecords){
//all updates finished, except for given read only records
},
scope: that
});
that._createCustomStore(data);
},
_createCustomStore: function(data) {
me = this;
Ext.create('Rally.data.custom.Store', {
data: data,
//model: 'PortfolioItem/' + _newParent.get('PortfolioItemTypeName'),
autoSync:true,
listeners: {
load: function(store,data,success) {
console.log("store value", store);
console.log("data value", data);
console.log("success value", success);
},
scope: me
},
});
},
onqModelRetrieved: function() {
var that = this;
that._type = 'PortfolioItem/' + that._type,
Rally.data.ModelFactory.getModel({
type: that._type,
success: this.onModelRetrieved,
scope: this
});
},
onModelRetrieved: function(model) {
this.model = model;
this.createFeature();
},
createFeature: function() {
var record = Ext.create(this.model, {
Name: "(Copy of) " + this._newObj.get('Name'),
});
record.save({
callback: function(result, operation) {
if(operation.wasSuccessful()) {
_newParent = result
Ext.Msg.alert('created ' + result.get('PortfolioItemTypeName') + ':', result.get('Name'));
}
else{
console.log("error");
}
}
});
}
});
其中_newParent definded?你在這段代碼中有幾個錯誤,一些額外的逗號,並且從父類中移除分號:copiedParent.get(「_ ref」); – 2014-10-03 09:21:58
@AlexG - 我相應地更新了代碼,代碼中沒有錯誤,它可以執行,我通過在複製代碼時錯誤地放了分號,現在我刪除它。 – Sontya 2014-10-03 09:33:19
好的,但我不明白你在哪裏定義_newParent?您正在使用它,但從未定義。 – 2014-10-03 09:36:30