javascript - Filter Collection by Substring in Backbone.js -


if want autocomplete collection, best way? i'd see if search string in (or select few) attributes in model.

i thinking like...

this.collection.filter(function(model) {     return model.values().contains($('input.search]').val()); }) 

edit i'm sorry, must not have explained enough. if have collection attributes...

[    { first: 'john', last: 'doe'},    { first: 'mary', last: 'jane'}  ] 

i want type in a search, catch keyup event, , filter out { first: 'mary', last: 'jane'}, neither john nor doe contains a.

you can @ model's attributes this...

var search = $('input.search]').val(); this.collection.filter(function(model) {     return _.any(model.attributes, function(val, attr) {         // comparison of value here, whatever need         return ~val.indexof(search);     });; }); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -