我有一个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中进行检查。
最佳答案
您的搜索功能应返回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);
}
Working fiddle
关于javascript - 重置后,Backbone.PageableCollection的fullCollection行为异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36519958/