更新时间:2023-10-23 15:25:22
什么是在骨干收集指定模型的目的
块引用>Backbone.Collection.extend({
网址:'/ REST /产品',
型号:型号
});基本上你说的集合中的每个型号
模式
的一个实例。这也是有益的这样col.add({
为prop1:富,
...
});和它会调用
新模式({为prop1:富,...})。
为你和它添加到集合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 thiscol.add({ prop1: "foo", ... });
And it will call
new Model({prop1: "foo", ... })
for you and add it to the collection.