1

我正在尝试可视化来自内部 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');
      }
    });

我定义了路由、订单模型、常见问题路由和适配器。我需要显示来自 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 " 

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

4

1 回答 1

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')
 });
于 2013-10-18T10:08:31.920 回答