Sunny Ho Sunny Ho - 1 year ago 106
jQuery Question

backbone confusion on collections and model

There's a folder of js/collections/contact.js and it has only

ContactManager.Collections.Contacts = Backbone.Collection.extend({
model: ContactManager.Models.Contact

The demo of a small app :

I'm trying to guess what does it do, but have no clue so far.

Answer Source

It only creates a new collection type and demonstrate how to encapsulate each component of an app. This project uses the global object ContactManager as a kind of namespace for the app.

The collection is used here:

var contacts = new ContactManager.Collections.Contacts(data.contacts),

And is equivalent to:

var contacts = new Backbone.Collection(data.contacts, {
    model: ContactManager.Models.Contact

Which mean each object inside data.contacts is made into a ContactManager.Models.Contact model object.

Additional documentation:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download