我陷入了不应该回来的境地id
API 端点中的字段。我需要告诉 ember 使用slug
字段为 / 而不是id
.
I tried DS.RESTAdapter.map('App.Post', id: {key: 'slug'})
。虽然这对于App.Post.find("a-slug-name")
,它搞乱了App.Post.find()
导致每次调用时都会添加一个新模型。并且还分配id
为空。
那么我该怎么做呢。
您需要指定应用作primaryKey
在你的适配器中。如果你想要slug
财产作为您的Post
model id
,定义primaryKey
在你的适配器上像这样:
DS.RESTAdapter.map('App.Post', {
primaryKey: 'slug'
});
Update
截至 Ember 数据版本1.0.0-beta.7 canary
,您需要执行此操作而不是上面的代码片段:
App.PostSerializer = DS.JSONSerializer.extend({
primaryKey: 'slug'
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)