且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么要在指定收集骨干示范

更新时间:2023-10-23 15:25:22


  

什么是在骨干收集指定模型的目的


块引用>
  Backbone.Collection.extend({
  网址:'/ REST /产品',
  型号:型号
});

基本上你说的集合中的每个型号模式的一个实例。这也是有益的这样

  col.add({
  为prop1:富,
  ...
});

和它会调用新模式({为prop1:富,...})。为你和它添加到集合

.MODEL

What is the aim of specifying a model in a Backbone collection? It seems that the collection need its own url. Why do this:

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

Instead of:

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

With a model like this:

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

Is there a way to group url declaration?

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

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

Basically your saying every model inside the collection is an instance of Model. It's also useful for doing this

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

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

.model