简体   繁体   中英

Ember Data 1.0 Error while loading route: TypeError: Cannot set property 'typeKey' of undefined

I am trying to visualize data from an internal Laravel PHP API. So my localhost:8000/api/orders outputs json that looks like the following:

[
    {
        "id": "2",
        "topic": "yusdvhdsh",
        "data": ""
    },
    {
        "id": "3",
        "topic": "praise",
        "data": ""
    }
]

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

I defined the routes, the order model, the faqroute and the adapter. I need to display a listing of the topics from this JSON data from localhost:8000/api/orders To be displayed in the faq template that looks like the one below:

<script type="text/x-handlebars" data-template-name="faq">
     <h5>faqs</h5>
    {{#each model}}
         {{topic}}
    {{/each}}

</script>

But when I try to access localhost:8000/#/faq it does not display anything and I get the following error on my console:

"Assertion failed: Error while loading route: TypeError: Cannot set property 'typeKey' of undefined " 

Let me know what I am doing wrong...

Ember data expects the response like this

{
  "orders": [
  {
    "id": "1",
    "topic": "Rails is unagi",
    "data": "Rails is unagi"
  }, 
  {
    "id": "2",
    "topic": "Omakase O_o",
    "data": "Rails is unagi"
  }]
}

Additionally you shouldn't define id on the class definition

 App.Order = DS.Model.extend({
    topic: DS.attr('string'),
    data: DS.attr('string')
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM