我有一个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。
答案 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);
}