Backbone.js: Module 6 get() / getByCid()
by emgee
HTML
<script src="http://documentcloud.github.com/underscore/underscore.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone.js"></script>
JavaScript
var collection = new Backbone.Collection();
collection.add(new Backbone.Model({name: "Fred", age: 30}));
console.log(collection.at(0).cid);
console.log(JSON.stringify(collection.get("c1")));
console.log(JSON.stringify(collection.get("c3")));
collection.add({name: "Barney", age: 27});
collection.add([
new Backbone.Model({name:"Wilma", age: 28}),
new Backbone.Model({name:"Betty", age: 25})
]);