collection.model

modelcollection.model([attrs], [options])
Override this property to specify the model class that the collection contains. If defined, you can pass raw attributes objects (and arrays) to add, create, and reset, and the attributes will be converted into a model of the proper type.

var Library = Backbone.Collection.extend({
  model: Book
});

A collection can also contain polymorphic models by overriding this property with a constructor that returns a model.

var Library = Backbone.Collection.extend({

  model: function(attrs, options) {
    if (condition) {
      return new PublicDocument(attrs, options);
    } else {
      return new PrivateDocument(attrs, options);
    }
  }

});
doc_Backbone
2016-04-17 12:21:24
Comments
Leave a Comment

Please login to continue.