重置后,Backbone.PageableCollection的fullCollection行为很奇怪

时间:2016-04-09 16:57:03

标签: javascript backbone.js backbone.paginator

我有一个Backbone.Pageable集合,我试图在其上进行过滤,但是使用过滤后的值重置集合,但在重置之后,collection.fullCollection的模型比原始模型少一个。

这是我的收藏:

var todoCollection = Backbone.PageableCollection.extend({
  mode:'client',
  search: function(letters){
    var self = this;
    if(letters === "") return this.fullCollection.models;

    var pattern = new RegExp(letters,"i");
    return this.fullCollection.filter(function(data) {
      return pattern.test(data.get("text"));
    });
  }
});

你可以查看这个小提琴here

1 个答案:

答案 0 :(得分:0)

您的搜索功能应返回todoCollection的实例。

var todoCollection = Backbone.PageableCollection.extend({

mode:'client',
  search: function(letters){
    var self = this;
    if(letters === "") return this.fullCollection.models;

    var pattern = new RegExp(letters,"i");
    result =  this.fullCollection.filter(function(data) {
      return pattern.test(data.get("text"));
    });
    return new todoCollection(result);
  }

here