[英]Backbone.js : can't get collection.get to work
This is so strange. 这太奇怪了。
I do 我做
console.log(this.collection);
And I can see all my models fine with its IDs attached correctly. 我可以看到我的所有型号都正确,其ID正确附加。
But on the same line, I do 但在同一条线上,我做到了
console.log(this.collection.get(1));
And it tells me it's "undefined". 它告诉我它是“未定义的”。
What's going on? 这是怎么回事?
EDIT : Just wondering, does "id" have to be unique? 编辑:只是想知道,“id”必须是独一无二的吗? I have some models that have no "ids" and then others have IDs set.
我有一些没有“ids”的模型,然后其他模型设置了ID。 Does this matter?
这有关系吗?
你必须at(1)
而不是get(1)
, get()
在集合中寻找一个元素,而at()
正在查看一个位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.