The two Backbone collection methods I use most often are probably where(), and toJSON(). However, they're difficult to use together sometimes. For example, I can filter my collection before I actually do anything with it using where()
, but this gives me back an array of models. I can't do further Lodash processing on this array, because it has full-fledged models, not objects in it. I can't pass this array to my template context because, again, it's looking for plain objects, and not Backbone model instances.
Showing posts with label where. Show all posts
Showing posts with label where. Show all posts
Monday, March 31, 2014
Backbone: Combining The where() and toJSON() Collection Methods
Wednesday, February 26, 2014
Lodash Where Inclusive Or
I really like using the Lodash where() function for filtering arrays. Something about it makes for elegant, condensed code — two very big wins in my opinion. For example, you can pass complex conditions in an object that test for property value equality. Each property is "and"ded together. The where()
function loses some of it's power when you want to combine expressions using "and" and "or". Often, the result is me writing a function to do the complex filtering, and passing that to where()
. But there's another way to do it.
Labels:
inclusiveor
,
lodash
,
uniq
,
where
Subscribe to:
Posts
(
Atom
)