2014-10-03 19 views
0

在我的應用程序,當我試圖複製一個對象它的複製,但如果我定義另一個函數調用,正確執行的代碼會給出錯誤,不知道爲什麼。任何幫助的高度讚賞,並感謝提前評論一個功能代碼的作品,否則它失敗

如果我評論此功能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"); 
         } 
        } 
       }); 
      }  
     }); 
+0

其中_newParent definded?你在這段代碼中有幾個錯誤,一些額外的逗號,並且從父類中移除分號:copiedParent.get(「_ ref」); – 2014-10-03 09:21:58

+0

@AlexG - 我相應地更新了代碼,代碼中沒有錯誤,它可以執行,我通過在複製代碼時錯誤地放了分號,現在我刪除它。 – Sontya 2014-10-03 09:33:19

+0

好的,但我不明白你在哪裏定義_newParent?您正在使用它,但從未定義。 – 2014-10-03 09:36:30

回答

0

嘗試定義它,使用它是這樣的:

_newParent: null, 
_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 = that._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 that = this; 
    var record = Ext.create(this.model, { 
     Name: "(Copy of) " + this._newObj.get('Name') 
    }); 
    record.save({ 
     callback: function (result, operation) { 
      if (operation.wasSuccessful()) { 
       that._newParent = result 
       Ext.Msg.alert('created ' + result.get('PortfolioItemTypeName') + ':', result.get('Name')); 
      } 
      else { 
       console.log("error"); 
      } 
     } 
    }); 
} 
+0

在這裏,你正在使_newParent爲null,所以被分配下邊的結果值不見了,所以它給錯誤提供了'Uncaught TypeError:無法讀取屬性'get'null [ – Sontya 2014-10-03 10:10:36