[英]Backbone.js collection get does not work
var sgt1 = Backbone.Collection.extend({
model: sgt2
});
var a = new sgt1();
a.add({attr1: 'asd'});
Ok, up to now it is works but: 好的,到目前为止它是有效的但是:
a.get(0)
returns undefined a.get(0)
返回undefined
and 和
a.at(0)
returns an obj a.at(0)
返回一个obj
Why does get
return undefined
? 为什么
get
回报undefined
?
With get()
you query the collection by the models id
field and not by its index like with at()
. 使用
get()
您可以通过模型id
字段查询集合,而不是使用at()
查询其索引。 Please refer to the documentation . 请参阅文档 。
a.get(0)
fetches by ID. a.get(0)
按ID获取。 It is not the same as at
which fetches by index position. 它是不一样的
at
其通过索引位置取出。 Since your model does not yet have an ID, get
would not work. 由于你的模型还没有一个ID,
get
是行不通的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.