简体   繁体   English

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

[英]Event Binding in Backbone.Marionette context

I am wondering why _.bindAll(this, ['onSortRemove']); 我想知道为什么_.bindAll(this, ['onSortRemove']); in the following code (1) rises the following error: 在以下代码(1)中出现以下错误:

Uncaught TypeError: Object [object Window] has no method 'resetItemViewContainer' 未捕获的TypeError:对象[对象窗口]没有方法'resetItemViewContainer'

To get things working I need to implement the following code _.bindAll(this); 为了使工作正常,我需要实现以下代码_.bindAll(this); .

My question is: should _.bindAll(this, ['onSortRemove']); 我的问题是:应该_.bindAll(this, ['onSortRemove']); be enough? 足够? if not, why? 如果没有,为什么?


(1) (1)

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

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

Syntax error 语法错误


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

The documentation's syntax of [*methodnames] is not saying "wrap this in an array". 文档的[*methodnames]的语法并不是说“将它包装在一个数组中”。 That's old-school documentation style to say "method names is optional, it can be zero or more arguments, comma-delimited". 这是老式的文档样式,说“方法名称是可选的,它可以是零个或多个参数,以逗号分隔”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM