作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 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);
}
关于javascript - Backbone.PageableCollection 的 fullCollection 重置后行为怪异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36519958/
我有一个 Backbone.Pageable 集合,我尝试对其进行过滤,但使用过滤后的值重置该集合,但重置后,collection.fullCollection 的模型比原始模型少一个。 这是我的收藏
我是一名优秀的程序员,十分优秀!