即使我在对应的模型中设置了 idAttribute,我也无法通过其 ID 获取单个模型。
一个集合看起来像这样:
[
{
"_account": "51dc04dbe4e643043d000001",
"name": "test.png",
"type": "image/png",
"_id": "51ff833f0342ee0000000001",
"added": "2013-08-05T10:49:35.737Z"
}
]
// Inside the Model I defined idAttribute
FileModel = Backbone.Model.extend({
idAttribute : "_id",
urlRoot : "/api/file"
[...]
}
// The collection contain each of the Model items
// but if I try to get a single model item by id:
Collection.get("51ff833f0342ee0000000001") -> the result is undefined
我不知道为什么,Backbone.Collection get model by id的解决方案不是解决问题的关键。