JsonAPI 与 Ember 数据的嵌套关系
JsonAPI nested relationships with Ember Data
我正在尝试处理具有嵌套关系的 JSONAPI 响应。 Ember-Data 当前正在获取 'included' 属性 中的所有数据并将其全部推送到正确的模型中,但是我的 'transcription' 对象和 'cuepoint' 对象不工作。 'video' 和 'transcription' 对象之间的关系工作正常,所以它是我需要帮助的具体嵌套部分。
这是我使用的数据示例:
{
"data":{
"type":"video",
"id":"55e0687ba1f9e8032c549680",
"attributes":{
"title":"Test32"
},
"relationships":{
"transcriptions":{
"data":[
{
"relationships":{
"cuepoints":{
"data":[
{
"id":"55e9b62446942224a0f456cc",
"type":"cuepoint"
}
]
}
},
"id":"55e0687ba1f9e8032c549680-transcription-0",
"type":"transcription"
}
]
}
}
},
"included":[
{
"type":"transcription",
"id":"55e0687ba1f9e8032c549680-transcription-0",
"attributes":{
"language":"English"
}
},
{
"type":"cuepoint",
"id":"55e9b62446942224a0f456cc",
"attributes":{
"cueIndex":0,
"startTimeMilliseconds":0,
"endTimeMilliseconds":4400,
"text":"- The first one is the L'Oreal Paris Extraordinary Oil."
}
}
]
}
知道我该如何处理吗?
虽然我没有测试过这个特殊情况,但您的 JSON 似乎不合规。
在顶级 relationships
键下,放置 "relationship" 个对象,在 included
中放置 "resource" 个对象。资源对象包含关系定义。
简而言之,将嵌套关系移出顶级 relationships
并移至 included
。
我正在尝试处理具有嵌套关系的 JSONAPI 响应。 Ember-Data 当前正在获取 'included' 属性 中的所有数据并将其全部推送到正确的模型中,但是我的 'transcription' 对象和 'cuepoint' 对象不工作。 'video' 和 'transcription' 对象之间的关系工作正常,所以它是我需要帮助的具体嵌套部分。
这是我使用的数据示例:
{
"data":{
"type":"video",
"id":"55e0687ba1f9e8032c549680",
"attributes":{
"title":"Test32"
},
"relationships":{
"transcriptions":{
"data":[
{
"relationships":{
"cuepoints":{
"data":[
{
"id":"55e9b62446942224a0f456cc",
"type":"cuepoint"
}
]
}
},
"id":"55e0687ba1f9e8032c549680-transcription-0",
"type":"transcription"
}
]
}
}
},
"included":[
{
"type":"transcription",
"id":"55e0687ba1f9e8032c549680-transcription-0",
"attributes":{
"language":"English"
}
},
{
"type":"cuepoint",
"id":"55e9b62446942224a0f456cc",
"attributes":{
"cueIndex":0,
"startTimeMilliseconds":0,
"endTimeMilliseconds":4400,
"text":"- The first one is the L'Oreal Paris Extraordinary Oil."
}
}
]
}
知道我该如何处理吗?
虽然我没有测试过这个特殊情况,但您的 JSON 似乎不合规。
在顶级 relationships
键下,放置 "relationship" 个对象,在 included
中放置 "resource" 个对象。资源对象包含关系定义。
简而言之,将嵌套关系移出顶级 relationships
并移至 included
。