gpt4 book ai didi

javascript - Backbone.PageableCollection 的 fullCollection 重置后行为怪异

转载 作者:行者123 更新时间:2023-11-28 06:09:41 27 4
gpt4 key购买 nike

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

你可以查看这个 fiddle 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com