javascript - Using _.matches() and to filter Backbone models -


i want filter backbone models have multiple key/value paris equal. example, want match all/first model has id of 123 , name 'john'.

i realize there other ways this, leverage matches() method.

is possible use underscore's matches() method create function pass filter or find find backbone model?

var search_fn = _.matches({id: 123, type: 'john'}); var should_be_active = _.find(master_model_array, search_fn); 

yes, should work, similar have done using "filter".

to reiterate:

// sample data var x = {name:"j", id: 1},     y = {name: "j", id: 2},     z = {name: "j", id: 1, more: "data"},     match = _.matches({name: "j", id: 1}); var list = [x,y,z];  var result = _.filter(list, match); 

this results in x , z matches criteria. jsfiddle

hope helps.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -