2
我只是努力使用下划线与骨干收集。骨干不能使用“this”?
var collection=Backbone.Collection.extend({
model:someModel,
getModelEntry : function(id){
return this.get(id);
//returns undefined
}
})
尝试2:
var collection=Backbone.Collection.extend({
model:someModel,
getModelEntry : function(id){
var model = this.where({id:id})[0];
//here I got model
return model.get("attr");
//returns undefined
}
});
什么错在收集使用get?
get正在实例中运行完美!
var coll=new collection;
coll.get(id); //working fine
嗯,这是奇怪的,我做了一个快速的jsfiddle和它的作品:小提琴(http://jsfiddle.net/y7gDN/)(检查控制台输出)。 – Ingro
'coll.getModelEntry(id)'返回'undefined'?很奇怪.. –
检查你的骨干模型的idAttribute没有被设置为别的东西而不是id? – jbl