Reputation: 4285
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...
Upvotes: 1
Views: 4444
Reputation: 47367
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')
});
Upvotes: 3