my api api/customers
return:
{
"value": [
{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"id": "b0d16ed0-c901-4ca3-ba41-7fc74c96909f"
},
{
"CustomerID": "ANATR",
"CompanyName": "Ana Trujillo Emparedados y helados",
"ContactName": "Ana Trujillo",
"ContactTitle": "Owner",
"id": "3f8ac226-9f78-42df-b337-0505f69792c3"
},
{
"CustomerID": "ANTON",
"CompanyName": "Antonio Moreno Taquería",
"ContactName": "Antonio Moreno",
"ContactTitle": "Owner",
"id": "09d31df6-69f4-43e4-9cc6-7faa5b8b5e3b"
}
]
}
but ember(/customers
) should expects:
{
"customers": [
{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"id": "b0d16ed0-c901-4ca3-ba41-7fc74c96909f"
},
{
"CustomerID": "ANATR",
"CompanyName": "Ana Trujillo Emparedados y helados",
"ContactName": "Ana Trujillo",
"ContactTitle": "Owner",
"id": "3f8ac226-9f78-42df-b337-0505f69792c3"
},
{
"CustomerID": "ANTON",
"CompanyName": "Antonio Moreno Taquería",
"ContactName": "Antonio Moreno",
"ContactTitle": "Owner",
"id": "09d31df6-69f4-43e4-9cc6-7faa5b8b5e3b"
}
]
}
I find this answer: GET unconventional JSON with Ember-data
so I try(in my app/serializers/customers.js):
export default DS.RESTSerializer.extend({
extractArray: function(store, type, payload, id) {
var newpayload = { customers: payload.value };
return this._super(store, type, newpayload, id);
},
});
and in the app/routes/customers.js
export default Ember.Route.extend({
model: function() {
return this.store.find('customer');
}
});
in the app/models/customer.js
export default DS.Model.extend({
CustomerID: DS.attr('string'),
CompanyName: DS.attr('string'),
ContactName: DS.attr('string'),
ContactTitle: DS.attr('string'),
});
and in the app/templates/customers.hbs:
{{#each}}
{{CustomerID}}({{ContactName}}
{{/each}}
I open the browser, but it's empty, and no error message, so why it doesn't work?