2013-07-25 25 views
1

我在无限分页 (http://addyosmani.github.io/backbone.paginator/examples/infinite-paging/index.html)工作Backbone.Marionette和Backbone.Paginator。 CompositeView中重新描绘

我使用CompositeView中的分页视图。

而我有以下问题。每当我得到新的数据部分后,Paginator的集合会删除旧数据并添加新数据,因此它使得CompositeView能够重新渲染并清除旧结果。

我该如何解决这个问题?我在考虑禁用重新提交功能,但是应该如何正确完成?

在此先感谢!

var BaseFeedChronoCompositeView = Backbone.Marionette.CompositeView.extend({ 
    tagName: "div", 
    template: _.template(ChronoFeedComposite_html), 
    itemView: Article,     
    events: { 
     'click #loadmore-button-manual': function (e) { 
      e.preventDefault(); 
      this.collection.requestNextPage(); 
    }, 

    appendHtml: function (collectionView, itemView, index) { 
     collectionView.$("#chronoFeed-content").append(itemView.$el); 
    } 
}); 

这里是基本代码。 012.this.collection.requestNextPage() - 向服务器发送数据请求。获取数据后,this.collection删除旧模型并添加新模型。

复合视图正在侦听这些事件并删除旧模型的itemView并为新模型添加itemView。

我需要CompositeView不要删除旧的itemViews。

+0

请添加一些代码的 – nstCactus

+0

临时的解决办法是:的CollectionView $( “#chronoFeed内容”)追加(ItemView控件$ el.clone(真));所以我将itemViews克隆添加到主视图。 – Roman

回答

0

我不太清楚这个分页器是如何工作的,因为我从来没有使用它。但我认为解决这个问题的最简单方法是确保您的收藏不删除旧模型。我假设当您的数据被返回时,它正在对集合执行set。如果你看一下骨干文档,你可以看到你可以删除模型http://backbonejs.org/#Collection-set

禁用此方法如果您想自定义的行为,你可以用 选项禁用它:{补充:假}, {remove:false}或{merge:false}。

所以,当你正在更新的集合,而不是只调用

myCollection.set([o1,o2,o3]); 

你应该做

myCollection.set([o1,o2,o3], {remove:false}); 
+0

this.collection.requestNextPage({remove:false})诀窍。谢谢! – Roman

相关问题