Ember.js REST 适配器期望 JSON 返回为:
{
"customer": {
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"id": "b0d16ed0-c901-4ca3-ba41-7fc74c96909f"
}
}
但是我的 API 返回的数据没有根元素:
{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"id": "b0d16ed0-c901-4ca3-ba41-7fc74c96909f"
}
我在这里发现一个问题:Ember.js REST Adapter without JSON root ,但答案太旧了,不起作用 在最新版本的 ember 和 ember-data 中。
抱歉我的英语不好,希望我说得清楚......
最佳答案
在序列化器中覆盖serializeIntoHash
:
serializeIntoHash: function(data, type, record, options) {
Ember.merge(data, this.serialize(record, options));
}
对于第二个问题,请查看typeForRoot
。为什么不直接阅读有关适配器的整个页面?
关于javascript - Ember.js REST 适配器使用 JSON 根(使用 ember-data),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30149353/