2017-06-28 26 views
0

我在Ember中進行API調用,並且我正在打的API正在返回一些帶有'ID'大寫的JSON,看起來Ember正在尋找小寫'id'。一切都應該工作,那麼在這種情況下,我將如何序列化這一塊JSON?Ember序列化'ID'

請參閱下面的JSON。

{ "ID": 2, "name": "Main Menu", "slug": "main-menu", "description": "", "count": 4, "items": [ { "id": 11, "order": 1, "parent": 0, "title": "Contact", "url": "http://localhost:8888/contact/", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 7, "object": "page", "object_slug": "contact", "type": "post_type", "type_label": "Page" }, { "id": 12, "order": 2, "parent": 0, "title": "About", "url": "http://localhost:8888/about/", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 5, "object": "page", "object_slug": "about", "type": "post_type", "type_label": "Page", "children": [ { "id": 21, "order": 3, "parent": 12, "title": "About Us – Sub", "url": "http://localhost:8888/about/about-us-sub/", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 9, "object": "page", "object_slug": "about-us-sub", "type": "post_type", "type_label": "Page" } ] }, { "id": 13, "order": 4, "parent": 0, "title": "Home", "url": "http://localhost:8888/home/", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 2, "object": "page", "object_slug": "home", "type": "post_type", "type_label": "Page" } ], "meta": { "links": { "collection": "http://localhost:8888/wp-json/wp/v2/menus/", "self": "http://localhost:8888/wp-json/wp/v2/menus/2" } } }

回答

0

您可以通過創建特定模型串行定義primaryKey: 'ID'。閱讀更多信息https://guides.emberjs.com/v2.13.0/models/customizing-serializers/#toc_ids

+0

謝謝!嘗試了這一點,我得到了一個新的錯誤,這是我以前從未見過的錯誤。我將如何導航?警告:在有效載荷中遇到「ID」,但沒有爲模型名「id」找到模型(解析的模型名稱使用(未知的mixin).modelNameFromPayloadKey(「ID」))'''有一些在與我上面顯示的JSON(slug,name等等)的關係 –

+0

如果你是usinv json-api,那麼你需要遵循json-api格式..我認爲它的響應數據格式問題 – kumkanillam

+0

我在REST上使用這個。 –