2012-05-04 98 views
0

的我有一个模型骨干图。绑定改变外部模型

此外,我有一个全球性的藏品一些特定应用的东西。

现在,我这个模型的变化事件绑定到我的视图的渲染方法,但是这似乎并没有工作。

model: new Preferences.Item(), 

render: function() { 

    $(that.el).html(template(that.model.toJSON()));     
}, 

initialize : function() { 
     this.render = _.bind(this.render, this); 
     // global account model holder 
      App.Storage.account.bind("change", this.render); 
}, 

我必须做一些特定的绑定来附加到外部模型的事件吗?

回答

0

找到了解决办法...你必须调用:

App.Storage.account.on("change", this.render) 
1

你应该绑定render方法用骨干的直列结合。此外,您在render方法中使用了that,这将是一个错误。

var ModelView = Backbone.View.extend({ 
    model: new Preferences.Item(), 
    template: _.template('<div><%= variable %></div>'); 
    render: function() { 
     this.$el.html(this.template(this.model.toJSON())) 
    }, 
    initialize: function() { 
     App.Storage.account.on('change', this.render, this); 
    } 
});