1

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

1 Answer 1

3

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')
 });
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer, Now I do not get an error but I also do not see the topics listed from the model.
Oops, I found a problem in the way I was trying to display the records in my template. It should be {{#each model}} {{topic}} {{/each}} I have corrected that part of my question. Your answer worked. Thanks once again.
Awesome, btw, Ember Data went through quite a big transition between RC13 and 1.0 beta. I'd recommend a glance over it before searching the web for most answers since so many things changed. It will save you a lot of problems. github.com/emberjs/data/blob/master/TRANSITION.md

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.