2012-05-04 43 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); 
    } 
});