我在Backbone中擁有此視圖,該視圖根據用戶操作更改其事件。Backbone將一個視圖事件複製到另一個
所以我有三個意見,都已經初始化了。
var view1 = new MainView({el : '#view1'});
var view2 = new ProductsView({el : '#prodcuts'});
var view3 = new StoresView({el : '#stores'});
現在我想要做的就是複製事件從一個視圖到另一個,然後更新意見報。我已經試過:
if($option == 'products') {
view1.events = view2.events
$("div[data-role='content']", view1.el).html(content);
} else {
view1.events = view3.events
$("div[data-role='content']", view1.el).html(content);
}
的問題是,即使是現在的內容是一樣的,和元素是與事件的對應存在,但事件不再射擊。爲什麼會這樣,我該如何解決它?
您可以使用'view1。$(...)'而不是'$(...,view1.el)'來避免在'$()'參數末尾隱藏重要的'view1'引用。 –