我在模型中获取JSON并在模板上呈现正常,但是,我想在模板上访问此数组(项目)。这里的目标是在导航栏中动态呈现这些菜单项。
我的车把看起来像这样,
{{#each menus as |menu|}}
{{#each menu.items as |items|}}
{{items}}
{{/each}}
{{/each}}
并返回
[object Object] [object Object] [object Object]
有什么想法吗?
下面的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"
}
}
}