我的问题是我第一次加载页面并且 View 正确显示。显示函数执行动画,但是当我导航到不同的 View 并返回时,它不会动画,但仍然显示。在路由器中,我为导航到的每个页面创建一个新 View 。
我正在将集合保存到一个名为应用程序的全局中,以限制加载。当我每次重新创建集合时,显示动画都会起作用,这让我认为它在渲染方法中。我认为这可能与 jquery 缓存了旧元素有关,当我再次将模板添加到页面时,选择器正在寻找旧元素而不是新元素。
我的页面 View 代码如下。就像我说的,它第一次工作正常,但第二次动画没有发生。
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;
}
最佳答案
我也有同样的问题。 当backbone try catch jquery对象时存在不兼容性。 我直接使用select的jquery解决了它
关于javascript - Backbone Jquery show() 在第二次加载时没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15935167/