2013-04-10 60 views
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; 
} 

回答

1

我有同样的问题。 主干尝试捕获jQuery对象时存在不兼容问题。 我解决了它使用直接选择的jquery

相关问题