I'm trying to normalize some non conventional json data from server to be used in ember.
The json response looks like this
{
"pagingAndSorting": {
"pageSize": 2,
"ascending": false,
"pageNumber": 5
},
"list": [
{
"recommendedDosage": "400mg Tablets",
"active": true,
"name": "ANT-Norfloxacin",
"id": "FE102EDA-984A-41A3-B9C8-3E13B98A864A",
"identifiers": []
},
{
"recommendedDosage": "",
"active": true,
"name": "ANT-Penicillin Injection",
"id": "F8DE6184-0F91-4DA9-A611-2B78F4B85D25",
"identifiers": []
},
{
"recommendedDosage": "",
"active": true,
"name": "ANT-Spectinomycin",
"id": "73205995-0CF2-4744-A856-F74B81355661",
"identifiers": []
}],
"fullListSize": 574
}
I created the following models
in app/model/paging-and-sorting.js
import DS from 'ember-data';
export default DS.Model.extend({
pageNumber : DS.attr('number',{defaultValue: 0}),
pageSize : DS.attr('number',{defaultValue: 40}),
ascending : DS.attr('boolean', {defaultValue: false})
});
in app/models/medicine.js import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('String'),
identifiers: DS.attr(''),
active: DS.attr('Boolean',{defaultValue: true}),
id: DS.attr('String'),
recommendedDosage : DS.attr('String')
});
In app/models/medicine-list.js
import DS from 'ember-data';
export default DS.Model.extend({
pagingAndSorting: DS.belongsTo('paging-and-sorting'),
list: DS.hasMany('medicine'),
fullListSize: DS.attr('number')
});
In app/serializers/medicine-list.js i have
import DS from 'ember-data';
//For the embedded Ember model
export default DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
pagingAndSorting : { embedded: 'always' },
list: { embedded: 'always' }
}
});
But this does not seem to be working. I'm not seeing any error in the console, however when i inspect using ember data it seems like no data gets into the ember store.
Am i missing something obvious? Does anyone have another solution/approach?
Thanks for your help!
Aucun commentaire:
Enregistrer un commentaire