gpt4 book ai didi

javascript - 加载路由 : TypeError: Cannot set property 'typeKey' of undefined 时出现 Ember Data 1.0 错误

转载 作者:行者123 更新时间:2023-11-30 12:55:08 24 4
gpt4 key购买 nike

我正在尝试可视化来自内部 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:8000/api/orders 的 JSON 数据中的主题列表,以显示在如下所示的常见问题解答模板中:

<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 " 

让我知道我做错了什么......

最佳答案

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')
});

关于javascript - 加载路由 : TypeError: Cannot set property 'typeKey' of undefined 时出现 Ember Data 1.0 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19445981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com