Why set the model in the layout

What is the purpose of model assignment in the Backbone collection? It seems that collections need their own url. Why is this:

Backbone.Collection.extend({
  url: '/rest/product',
  model: Model
});

Instead:

Backbone.Collection.extend({
  url: '/rest/product'
});

With this model:

var Model = Backbone.Model.extend({
  url: function() {
    return '/rest/product/' + this.id;
  }
});

Is there a way to group an ad url?

+3
source share
1 answer

What is the purpose of specifying a model in the Backbone collection

Backbone.Collection.extend({
  url: '/rest/product',
  model: Model
});

Basically, you say that every model within a collection is an instance Model. It is also useful for this.

col.add({
  prop1: "foo", 
  ...
});

And he will call new Model({prop1: "foo", ... })for you and add it to the collection.

.model

+11
source

All Articles