2014-03-03 33 views
0

當我從ArrayController中刪除項時,我不能調用未定義對象的方法'set'。不能調用未定義的餘燼的方法'集'

start: function() { 
    this.registerModel('listController', Ember.ArrayController.create()); 
    this._super(); 
}, 

我的視圖看起來像,

{{#each item in marketingListCriteriaList}}   
    {{view Select valueBinding="item.entity" contentBinding="controller.allEntities" optionLabelPath="content.Name" optionValuePath="content.Name" }} 
{{/each}} 

我有觀察 .observes一個觀察者方法( 'listController。@ each.entity')

上述觀察者被調用我時使用removeObject()方法從數組控制器中刪除對象。

有沒有其他方法可以從數組中刪除對象?

entityChangeObserver: function (thisModule) { 
    var thisModule = this; 
    var criteria = thisModule.get('listController.content'); 
    if (criteria != undefined && criteria.length > 0 && criteria[criteria.length - 1].entity != undefined) { 
     var presentObject = criteria[criteria.length - 1]; 
     $.each(thisModule.get('allEntities'), function (index, item) { 
      if (presentObject.entity === item.Name) { 
       presentObject.set('allAttributes', item.Attributes); 
      } 
     });   
    } 
}.observes('[email protected]'), 

attributeChangeObserver: function (thisModule) { 
    var thisModule = this; 
    var criteria = thisModule.get('listController.content'); 
    if (criteria != undefined && criteria.length > 0 && criteria[criteria.length - 1].attribute != undefined) { 
     var presentObject = criteria[criteria.length - 1]; 
     $.each(presentObject.get('allAttributes'), function (index, item) { 
      if (presentObject.attribute === item.Name) { 
       thisModule.setDefaulsVisibility(presentObject); 
       if (item.Type === '1') { 
        presentObject.set('textVisible', true); 
       } 
       else if (item.Type === '2') { 
        presentObject.set('selectVisible', true); 
        presentObject.set('allValues', item.Values);       
       } 
       else if (item.Type === '3') { 
        presentObject.set('multiSelectVisible', true); 
        presentObject.set('allValues', item.Values); 
       } 
       else if (item.Type === '4') { 
        presentObject.set('dateVisible', true); 
       } 
      } 
     }); 
    } 
}.observes('[email protected]'), 

回答

0

首先感謝後期的帖子。

我想出了「在被破壞的對象上調用set」問題的解決方案。

didInsertElement我的控制定義我做了檢查爲如果(!me.isDestroyed)爲每一套操作。

0

您也可以使用刪除數組元素「刪除」,而不是「的removeObject」不過,你可能要仔細檢查你的邏輯在你的觀察,當你刪除一個對象,它給出了不確定的錯誤。我會建議堅持刪除對象,並在觀察者中修正錯誤。另外,請注意,如果您正在循環數組,則使用「remove」將不會立即更新手柄模板。

+0

對不起,給出了錯誤的描述。我得到的錯誤是**對被銷燬的對象**進行調用。我在觀察者中處理了未定義的異常。 – Avinash

+0

發佈上面編輯過的觀察員觸發 – Jaime

+0

時調用的代碼 – Avinash

相關問題