Saturday, 15 March 2014

backbone.js - How to get models from a collection that have a certain attribute -


I want to get some models in my collection that have a specialty unit. My current method includes this,

  var unitIds = ciLocal.where ({unit:! Null}); Console.log (unitIds.length);   

The strange thing is that the removal!

Can someone suggest a good way of loop in my collection and return those models which are anything in the unit?

It is perhaps noteworthy that there are two values ​​in that unit, one unit unit and the other that is an array of other values, I need to bring the whole model back, not just the unit section.

In this screenshot you can see that 68 is the tap, while the object in 69 is

{" carID ":" 37 "," entity ": {" entity id ":" 37_Chaffinch_75 "," status history ": [{" lat ":" 51.474312 "," Long ":" - 0.491672 "," time ":" 2011-07-08 11:24:47 "," status ":" 1 "," estimated speed ":" 0 "," last soundfile name ": "Exit Car Park", "Last Ring Range": "10", "Last Sand Time": "2011-07-08 11:25:03", "isToday": false, "minutesAgo": 1028188} ]}, "Registration": "CJ1361-yiji", "color": "Luck "" "" Model ":" SDV8 "}

Filters _.filter (list, iterator, [reference])
Each value in the list Returning an array of all the values ​​passing a true test (iterator) through ./P>

In this way define any, non-zero value

  Var c = new Backbone.Collection ([{id: 1, unit: 1}, {id: 2, unit: null}, {id: 3}]); C.filter {var v = model.get ('unit'); return ((typef (v)! == 'undefined') & amp; (v! == faucet)}}   

and a demo

No comments:

Post a Comment