Reputation: 407
Can't access my requested Data (from REST API) from the template. For example to get a name or something like that, tried something with
{{model}} or {{App.Customer.name}}
But didn't worked.
JSON from API:
{
"customer": {
"name": "Omegasoft"
}
}
app.js Code:
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.get('store').find('customer');
}
});
App.ApplicationAdapter= DS.RESTAdapter.extend({
namespace: 'api/rest'
});
App.Customer = DS.Model.extend({
name: DS.attr()
});
Upvotes: 1
Views: 41
Reputation: 7464
It looks like your problem is with how you represent the data in your JSON API. Ember-data is expecting you to follow their naming conventions. So if you have a customer
model, the JSON you send to your app should look like this:
{
'customers': [{
'name': 'Omegasoft'
}]
}
In the template, as long as the model is linked, you should be able to just put {{name}}
in the template and Ember will be smart enough to link them.
If the template is getting sent an array, you'll also have to use {{#each}}
to iterate through each object.
I don't know if there are potentially other problems in your code as well.
Upvotes: 1