Ember数据:您的服务器返回了一个带有键0的散列,但是没有映射 [英] Ember data: Your server returned a hash with the key 0 but you have no mapping for it
问题描述
任何想法原因是?
型号:
App.Article = DS.Model.extend({
title:DS.attr('string')
});
JSON请求article.json的响应:
[
{
id:1,
title:Title 1
},
{
id:2,
title:Title 2
}
]
我认为原因是响应的格式...我已经改变了我的回应,包括文章,但同样的问题。 / p>
[
{
文章:{
id:1,
title:Title 1
}
},
{
article:{
id:2,
标题:标题2
}
}
]
在哪里可以找到一个关于JSOn请求和响应应如何格式化以用于RESTadapter的良好文档?
您正在寻找的JSON应该有一个根元素
{articles:[
{
ID :1,
title:Title 1
},
{
id:2,
title:Title 2
}
]
}
您可以在< a href =http://emberjs.com/guides/models/the-rest-adapter/#toc_sideloaded-relationships =nofollow> 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屋!