0
濾鏡模式我有一個集合作爲保持索引而從骨幹網收集
var Book = Backbone.Model.extend({
defaults:{
name: '',
author: ''
}
});
var BookCollection = Backbone.Collection.extend({
model: Book
});
/*** Populate the Collection ***/
var b1 = new Book({name: 'Java programming', author: 'John Doe'});
var b2 = new Book({name: 'C# programming', author: 'Alice Jane'});
var b3 = new Book({name: 'SQL in depth', author: 'James Wayne'});
var bkCollection = new BookCollection();
bkCollection.push(b1);
bkCollection.push(b2);
bkCollection.push(b3);
//I want to remove all models where name contains word 'programming'
var RESTRICTED = 'programming';
bkCollection.each(function(book){
if(book.get('name').indexOf(RESTRICTED) > -1){
bkCollection.remove(book);
}
});
然而,我最終得到不確定的模型和編程題在某些情況下,當有大量的記錄(> 100)
在Backbone中從集合中過濾出模型的正確方法是什麼?