对于骨干模型上的 id 来说,它只是id
并且全部小写。如果我在服务器上的Id被调用怎么办UserId
。在主干的解析方法中,我该如何更改UserId
to id
并对所有其他属性使用相同的名称?
For eg.
window.User = Backbone.Model.extend({
defaults:
{
UserId: 0, // <--can i just tell backbone that this is my id?
Name: '',
Age: 0
}
parse: function(response){
var model = response;
model.id = response.UserId;
return model;
}
});
有一个更好的方法吗?
告诉主干模型我的 id 类型如何UserId
.
你必须使用以下命令告诉 Backbone 你的 id 是什么属性id属性在模型中:
window.User = Backbone.Model.extend({
idAttribute: "UserId",
...
})
一切正常:)。主干将创建一个id
您的财产和该模型的收藏将get()
由你的UserId
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)