通常会将model change
事件绑定到render function
,如下所示:
initialize: function() {
this.model.bind('change', this.render, this);
}
如何将model change
事件绑定到render function with parameter
:
render: function(templ) {
this.$el.html(templ);
}
initialize: function() {
// ?
}
答案 0 :(得分:2)
这样的东西?
this.model.bind('change', function() {
return this.render(templ);
}, this);
答案 1 :(得分:1)
您可以使用underscore bind进行部分申请(这就是您想要做的事情)。
this.model.bind('change', _.bind(this.render, this, 'foo', 'bar'));
因此渲染接收'foo'和'bar'作为aguments