我有一个上下文菜单,其中包含菜单项和子菜单项。一个菜单可以有零个或多个子菜单项。我需要将我的菜单对象映射到一个 json 对象,如下所示。我该怎么做?
var commonMenuItems = [
{
Menu: "Print",
Caption: "Print"
},
SubMenuItems: [
{
SubMenuItemName: "PrintSelected",
SubMenuItemDisplayName: "Print Selected",
},
{
SubMenuItemName: "PrintAll",
SubMenuItemDisplayName: "Print All",
}
]
}
];
我想以编程方式将 commonMenuItems 数组映射到项目 json 对象项目。
items: {
"Print": {"name": "Print"
"items":{
"PrintSelected": {"name": "Print Selected"},
"PrintAll": {"name": "Print All"},
}
}