I'm trying to make ember work with a kind of custom API. The api response, for a single record, looks similar to this:
{
id: "12345",
name: "ObjName",
functions: [
"function1",
"function2"
],
participants: [
{
name: "participantName1",
role: "participantRole1",
definition: "participantDefinition1",
features: [
{
type: "feature1",
description: "featureDescription1"
},
{
type: "feature2",
description: "featureDescription2"
}
]
},
{
name: "participantName2",
role: "participantRole2",
definition: "participantDefinition2",
features: [
{
type: "feature1",
description: "featureDescription1"
},
{
type: "feature2",
description: "featureDescription2"
}
]
}
]
}
I'm able to retrieve the JSON and using the JSONSerializer I'm also able to map the attributes to the model:
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin';
export
default JSONSerializer.extend(EmbeddedRecordsMixin, {
normalizeFindRecordResponse(store, type, payload) {
return {
data: {
id: payload.ac,
type: type.modelName,
attributes: {
name: payload.name,
functions: payload.functions,
participants: payload.participants,
}
}
};
}
});
This is where I'm struggling. Since this is not a common API, I'm not sure how to make the embedded relationships accessible. In the template for this object, I have no problem to display , which displays the name attribute. But if I try to do something like this:
<li></li>
Nothing is displayed. Has anyone experience with such customised APIs?
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire