I have a problem with model and serializer. I've looked at the documentation and don't found a solution. My app connected to a django rest api.
Django response:
{
"id": 1,
"url": "http://localhost:8000/users/1/",
"username": "username",
"email": "xxx@email.com",
"is_staff": true
}
The model:
export default DS.Model.extend({
url : DS.attr('string'),
username : DS.attr('string'),
email : DS.attr('string'),
});
I've modify the response with a serializer to include "data":
export default DS.JSONAPISerializer.extend({
primaryKey: 'id',
normalizeFindRecordResponse(store, type, payload, id) {
console.log('payload',payload)
return {
data: {
'id': id,
'url': payload.url,
'username': payload.username,
'email': payload.email,
}
} ;
}
});
The route:
export default Ember.Route.extend({
model() {
return this.store.findRecord('users', 1);
}
});
Another version of the route same error:
export default Ember.Route.extend({
model() {
this.store.findRecord('users', '1').then(function(user){
console.log('user', user);
}).catch(function(e){
console.log('e', e);
});
}
});
Finally Ember inspector has the model but all values as undefined and "str is undefined" on console.
Thanks for your help and sorry for my english
Aucun commentaire:
Enregistrer un commentaire