【发布时间】:2015-07-06 14:01:54
【问题描述】:
我正在使用 Ember Data 1.13.3。我想使用 JSONAPISerializer 中的 normalizeResponse 将旧的 JSON 格式转换为新的 JSONAPI 格式。
例如,我的 json 来自像
这样的网络服务{
user: { id: 1, name: 'wecc', accounts: [1, 2] },
accounts: [
{ id: 1, email: 'wecc@sweden.se' },
{ id: 2, email: 'wecc@greece.gr' }
]
}
现在在我的 JSONAPISerializer 中,我如何从旧的 json 中获取 JSONAPI 格式。我正在使用旧格式。但我希望该格式自动转换为 JSONAPI。像下面一个
{
data: {
id: '1',
type: 'user',
attributes: {
name: 'wecc'
},
relationships: {
accounts: {
data: [
{ id: '1', type: 'account' },
{ id: '2', type: 'account' }
]
}
}
},
included: [{
id: '1',
type: 'account',
attributes: {
email: 'wecc@sweden.se'
}
}, {
id: '2',
type: 'account',
attributes: {
email: 'wecc@greece.gr'
}
}]
}
我从 ember 中找到了一些帮助。
http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_internal-format-change-to-json-api 他们建议使用 normalizeResponse
【问题讨论】:
标签: ember.js ember-data jsonserializer json-api