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

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -