1
我的問題是我第一次加載頁面並且視圖正確顯示。 show功能會動畫,但是當我導航到不同的視圖並返回時,它不會動畫,但仍然顯示。在路由器中,我爲每個導航到的頁面創建一個新的視圖。Backbone Jquery show()不會在第二次加載時產生動畫
我將集合保存到全局調用的應用程序中,以限制加載。當我每次重新創建集合時,展示動畫都會起作用,這使得我在渲染方法中想到它。我認爲這可能與jquery緩存舊元素的事實有關,並且當我再次將模板添加到頁面時,選擇器正在尋找舊元素而不是新元素。
我的頁面瀏覽代碼如下。就像我說的那樣,它第一次正常工作,但第二次沒有發生動畫。
initialize: function() {
if(!app.collections.boardsList)
app.collections.boardsList = new app.BoardsListCollection();
this.listenTo(app.collections.boardsList, "add", this.renderOne);
this.listenTo(app.collections.boardsList, "reset", this.render);
this.listenTo(app.collections.boardsList, "change", this.render);
this.render();
app.collections.boardsList.fetch();
this.interval = setInterval(function(){
app.collections.boardsList.fetch();
console.log("Fetching");
}, 10000);
},
render : function(){
this.$el.html(this.template());
this.renderAll();
return this;
},
renderAll : function(){
app.collections.boardsList.each(this.renderOne, this);
},
renderOne : function(item){
var container = !this.state ? "#left-list" : "#right-list";
var boardView = new app.BoardsItemView({
model : item
});
boardView.$el.hide();
boardView.render();
this.$el.find(container).append(boardView.$el);
boardView.$el.show("fast");
this.state = this.state ? 0 : 1;
}