【问题标题】:cannot call method 'set' of undefined ember无法调用未定义余烬的方法“set”
【发布时间】:2014-07-04 16:10:53
【问题描述】:

当我从 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('listController.@each.entity'),

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('listController.@each.attribute'),

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    您也可以使用“remove”而不是“removeObject”来删除数组元素,但是,您可能需要仔细检查观察者中的逻辑,当您删除对象时会出现未定义的错误。我建议坚持删除对象并仅修复观察者内的错误。另外,请注意,如果您在数组上循环,使用“删除”不会立即更新车把模板。

    【讨论】:

    • 抱歉描述有误。我得到的错误是在被破坏的对象上调用集合。我已经在我的观察者中处理了未定义的异常。
    【解决方案2】:

    首先对迟到的帖子表示抱歉。

    我想出了解决“在已破坏对象上调用集合”问题的解决方案。

    didInsertElement 的控件定义中,我为每个集合操作检查了 if (!me.isDestroyed)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-18
      • 2011-10-14
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多