2012-05-04 14 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); 
    } 
}); 
関連する問題