javascript - Filter Backbone collection on multiple model attributes -
javascript - Filter Backbone collection on multiple model attributes -
i have bit of problem how best filter backbone collection on models attributes. setup this:
i have collection several models in it. each model has attribute wich holds array of numbers ("type"). this:
- collection - model - id: 1 - name - phone - type [3] - model - id: 2 - name - phone - type [2] - model - id: 3 - name - phone - type [1,2] what want here able filter collections on models "type" attribute. have "type" attribute because contact list , each contact can of several types. e.g collection should able filtered on unlimited types. should able filter on lets type "1" , type "2" wich show model 2 , model 3. cause model 1 not have "type" 1.
any code examples or other help on great. thanks!
hi here code can filter multiple types, stored in array
var typestofilter=[5,1,2];//array of type tobe search. var f2=friends.filter(function(o){ var accept=false; $(typestofilter).each(function(i,val){ if(_.indexof(o.get('type'), val) >-1){ accept= true; } }) homecoming accept; }); and here jsfiddle.
javascript backbone.js filter
Comments
Post a Comment