我正在尝试从内部Laravel PHP API可视化数据。所以我的localhost:8000 / api / orders输出json,如下所示:
[
{
"id": "2",
"topic": "yusdvhdsh",
"data": ""
},
{
"id": "3",
"topic": "praise",
"data": ""
}
]
这是我的app.js
App.Router.map(function() {
this.route('introduction');
this.route('orders');
this.route('faq');
});
App.Order = DS.Model.extend({
id: DS.attr('string')
, topic: DS.attr('string')
, data: DS.attr('string')
});
App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api'
});
App.FaqRoute = Ember.Route.extend({
model: function() {
return this.store.find('order');
}
});
我定义了路由,订单模型,faqroute和适配器。我需要显示来自localhost的这个JSON数据的主题列表:8000 / api / orders要显示在faq模板中,如下所示:
<script type="text/x-handlebars" data-template-name="faq">
<h5>faqs</h5>
{{#each model}}
{{topic}}
{{/each}}
</script>
但是当我尝试访问localhost:8000 /#/ faq时它没有显示任何内容,我在控制台上收到以下错误:
"Assertion failed: Error while loading route: TypeError: Cannot set property 'typeKey' of undefined "
让我知道我做错了什么......
答案 0 :(得分:3)
Ember数据需要像这样的响应
{
"orders": [
{
"id": "1",
"topic": "Rails is unagi",
"data": "Rails is unagi"
},
{
"id": "2",
"topic": "Omakase O_o",
"data": "Rails is unagi"
}]
}
此外,您不应在类定义
上定义 id App.Order = DS.Model.extend({
topic: DS.attr('string'),
data: DS.attr('string')
});