1

我有一个 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"));
    });
  }
});

你可以在这里查看这个小提琴。

4

1 回答 1

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);
  }

工作小提琴

于 2016-04-10T03:55:35.633 回答