Ember Serialize' ID'

时间:2017-06-28 21:36:34

标签: ember.js

我正在Ember中进行API调用,而我正在点击的API会返回一些带有ID'资本化,似乎Ember正在寻找小写的“id。”#39;其他一切都应该有效,那么在这种情况下如何将这一段JSON序列化呢?

请参阅下面的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" } } }

1 个答案:

答案 0 :(得分:0)

您可以通过创建特定于模型的序列化程序来定义primaryKey: 'ID'。阅读更多信息https://guides.emberjs.com/v2.13.0/models/customizing-serializers/#toc_ids