I have an underscored API response and in my JSONSerializer
i’m overriding keyForAttribute
but it is not working and i placed a debugger in keyForAttribute
function it is not firing at all.
I also tried adding attr
properties but it is not working as well.
here is my Serializer:
import DS from "ember-data";
import { underscore } from "@ember/string";
export default DS.JSONSerializer.extend({
keyForAttribute(attr) {
return underscore(attr);
},
attrs: {
documentType: 'type',
coverUrl: "cover_url",
mainTopic: "main_topic",
publicationDate: "publication_date",
globalReads: "global_reads",
localReads: "local_reads"
},
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
return {
data: payload.documents.map((item, index) => {
return {
id: index,
type: "document",
attributes: item
};
})
};
}
});
and here is my model
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
coverUrl: DS.attr('string'),
authors: DS.attr(),
institution: DS.attr('string'),
documentType: DS.attr('string'),
publicationDate : DS.attr('date'),
mainTopic: DS.attr('string'),
globalReads: DS.attr('number'),
localReads: DS.attr('number'),
});
and here is part of my API response:
{"title": "World War 2",
"frequency": "Monthly",
"type": "THESIS",
"languages": [
"ENGLISH",
"ARABIC"
],
"doi": "10.1000/182",
"descriptors": [
"ARTS",
"PSYCHOLOGY"
],
"keywords": [
"history",
"adolf hitler",
"war"
],
"affiliation": "history",
"isbn": "978-92-95055-02-5",
"institution": "History Palace",
"eissn": 2312,
"pissn": 1595,
"document_id": "1",
"publication_date": 1512346539773,
"main_topic": "ARTS",
"document_abstract": "some document abstract here",
"cover_url": "http://ift.tt/2BQ9khs",
"content_url": "http://ift.tt/2BQ9khs",
"global_reads": 244,
"local_reads": 102,
"translated_title": "الحرب العالمية الثانية",
"dewey_number": "900-999",
"program_type": "MASTER",
"publishing_country": "NEW_ZEALAND"
},
any help would be very appreciated.
Thank you.
Aucun commentaire:
Enregistrer un commentaire