Retrieving Model Data

In notebook:
FrontEndMasters BackboneJS
Created at:
2016-06-10
Updated:
2016-06-10
Tags:
libraries JavaScript
Most used methods:
  • get
  • at
  • where
  • pluck

Get(id)

​library.add({id:14, artist: "Rusko", title: "Woo Boost"});
library.get(14).get("title");​ -> "Woo Boost"

This more efficient than filtering or ​where​. 
You can also use the ​Cid​, which is given automatically by Backbone (when you don't specify one, or the restful service doesn't give one).
​library.get("c1").get("title")

at(index)

retrieve by index in the collection

where(attributes)

filters the collection

pluck(attribute)

Retrieve an attribute value from each model. See previous note. It will return the attributes in an array.
and many more Underscore aliases.

Everything you can do in Underscore with arrays, you can do it in Backbone.