Backbone.Marionette上下文中的事件绑定

时间:2012-10-01 10:26:32

标签: javascript backbone.js bind underscore.js marionette

我想知道为什么以下代码(1)中的_.bindAll(this, ['onSortRemove']);会出现以下错误:

  

未捕获的TypeError:对象[对象窗口]没有方法   'resetItemViewContainer'

为了让工作正常,我需要实现以下代码_.bindAll(this);

我的问题是:_.bindAll(this, ['onSortRemove']);应该足够吗?如果没有,为什么?


(1)

    initialize: function () {
        _.bindAll(this, ['onSortRemove']); // it does not work
        _.bindAll(this); // it works
     }

    onSortRemove: function () {
        setTimeout(this.render, 0);
    }

1 个答案:

答案 0 :(得分:2)

语法错误


initialize: function () {
  _.bindAll(this, 'onSortRemove'); // <- no array wrapper
}

[*methodnames]的文档语法并没有说&#34;将它包装在数组&#34;中。这个&#34;方法名称的老式文档样式是可选的,它可以是零个或多个参数,逗号分隔&#34;。