2015-09-04 98 views
2

我正在嘗試處理嵌套關係的JSONAPI響應。 Ember-Data目前正在拾取'included'屬性中的所有數據,並將其全部推送到正確的模型中,但'轉錄'對象和'cuepoint'對象之間的關係不起作用。 「視頻」和「轉錄」對象之間的關係工作正常,所以它特別是我需要幫助的嵌套部分。JsonAPI與Ember數據嵌套關係

下面是我使用的數據的一個例子:

{ 
    "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." 
     } 
     } 
    ] 
} 

任何想法如何,我可以處理這個問題?

回答

2

雖然我沒有測試過這種特殊情況,但您的JSON看起來並不合規。

根據頂級relationships鍵,放置「關係」對象,並在included中放置「資源」對象。資源對象包含關係定義。

總之,將頂層relationships之外的嵌套關係移動到included之外。

+0

它是否在JSON API規範中的任何位置提及? –

+3

引用:「另外,資源對象可以包含以下任何頂級成員: attributes:表示資源數據的屬性對象 關係:描述資源與其他JSON API資源之間關係的關係對象 鏈接:包含與資源相關鏈接的鏈接對象 meta:元對象,包含有關無法表示爲屬性或關係的資源的非標準元信息。另見「A」關係對象上的位「必須至少包含以下之一......」 – aceofspades

+1

你是我的英雄。像魅力一樣工作。你的解決方案是絕對有道理的,但是我的大腦因此被絆倒了。謝謝! –