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

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -