vendredi 20 mars 2015

Get EmberJS working with array of objects

I have a simple EmberJS app to list and show various objects.


My /servers.json API (for example) return this kind of format:



[
{
"hosted_domain" : "example.com",
"status" : 1,
"name" : "srv0443",
"id" : 443
},
{
"id" : 392,
"status" : 1,
"name" : "srv0392",
"hosted_domain" : "example.com"
},
{
"hosted_domain" : "example.com",
"id" : 419,
"name" : "srv0419",
"status" : 1
}
]


But I got the following error:



Assertion Failed: The response from a findAll must be an Array, not undefined


Ember expects this kind of format:



{
"servers" : [
{
"name" : "srv0443",
"status" : 1,
"id" : 443,
"hosted_domain" : "example.com"
},
{
"status" : 1,
"name" : "srv0392",
"id" : 392,
"hosted_domain" : "example.com"
},
{
"status" : 1,
"name" : "srv0419",
"hosted_domain" : "example.com",
"id" : 419
},
]
}


I know I can override the payload with the extractArray of the RESTSerializer.


It's works by doing payload = { servers: payload } but how get it working in a generic way?


How can I do to catch the needed key of an Ember's controller?


In a more general way, what is the good REST format, by convention?


Thanks.





Aucun commentaire:

Enregistrer un commentaire