使用参数绑定渲染功能。 Backbone.js的

时间:2013-02-27 14:54:27

标签: javascript jquery backbone.js

通常会将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() {
    // ?
}

2 个答案:

答案 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