Ember 数据:您的服务器返回了一个密钥为 0 的散列,但您没有映射它 [英] Ember data: Your server returned a hash with the key 0 but you have no mapping for it
问题描述
我有一个简单的模型并使用 RESTadapter 来获取数据.执行了 JSON 请求,但随后我收到以下错误:您的服务器返回了一个密钥为 0 的散列,但您没有映射它"
知道是什么原因吗?
型号:
App.Article = DS.Model.extend({标题:DS.attr('string')});
请求articles.json的JSON响应:
<预><代码>[{身份证":1,"title": "标题 1"},{身份证":2,"title": "标题 2"}]我认为原因是回复的格式......我已经将回复更改为包含文章",但仍然存在同样的问题.
<预><代码>[{文章": {身份证":1,"title": "标题 1"}},{文章": {身份证":2,"title": "标题 2"}}]我在哪里可以找到关于如何格式化 JSOn 请求和响应以与 RESTadapter 一起使用的好的文档?
你要找的 JSON 应该有一个根元素
{"文章": [{身份证":1,"title": "标题 1"},{身份证":2,"title": "标题 2"}]}
您可以在 Ember Docs RESTAdapter 中找到文档或在 JSONapi 项目
I have a simple model and use the RESTadapter to get the data. The JSON request is executed, but then I receive the following error: "Your server returned a hash with the key 0 but you have no mapping for it"
Any idea what the reason is ?
Model:
App.Article = DS.Model.extend({
title: DS.attr('string')
});
JSON Response of request articles.json:
[
{
"id": 1,
"title": "Title 1"
},
{
"id": 2,
"title": "Title 2"
}
]
I think the reason is the format of the response ... I have already changed my response to include "article", but stil the same problem.
[
{
"article": {
"id": 1,
"title": "Title 1"
}
},
{
"article": {
"id": 2,
"title": "Title 2"
}
}
]
Where can I find a good documentation on how the JSOn request and response should be formatted for use with the RESTadapter ?
The JSON you are looking for should have a root element
{"articles": [
{
"id": 1,
"title": "Title 1"
},
{
"id": 2,
"title": "Title 2"
}
]
}
You can find documentation in the Ember Docs RESTAdapter or at the JSONapi project
这篇关于Ember 数据:您的服务器返回了一个密钥为 0 的散列,但您没有映射它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!