我正在尝试从json响应中动态加载复选框项,因为我在下面编写了代码,但它不起作用。
代码:
var mockData = { children: []};
if (parsedJSONObject.menuFunctions instanceof Array) {
$.each(parsedJSONObject.menuFunctions, function(i, obj) {
mockData.push({
item:{
id: obj.menuId,
menuDisplayName: obj.menuDisplayName,
checked: false
});
if (obj.hasOwnProperty("childMenus")) {
var childMenu = "";
if (obj.childMenus instanceof Array) {
$.each(obj.childMenus, function(j, childObj) {
mockData.children.push({
item:{
id:childObj.menuId,
menuDisplayName:childObj.menuDisplayName,
checked: false
});
});
}
}
});
}
}我的Json回复:
{"loginStatus":"Y","menuFunctions":[{"menuDisplayName":"My Document","menuId":"10127"},{"menuDisplayName":"Health
Topic","menuId":"10128","parentMenuId":"-1"},{"menuDisplayName":"Alerts","menuId":"10129","parentMenuId":"-1"},{"childMenus":[{"menuDisplayName":"Conditions","menuId":"10131","parentMenuI
d":"10130"},{"menuDisplayName":"Procedures and
Surgeries","menuId":"10132","parentMenuId":"10130"}]}我尝试了上面的代码,但是没有发生任何事情,我不知道我做错了什么。请帮帮忙。
发布于 2017-06-15 16:19:46
行mockdata.push中有一个语法错误
它应该是:
mockData.push({
item:{
id: obj.menuId,
menuDisplayName: obj.menuDisplayName,
checked: false
}});在json响应中也不正确
https://stackoverflow.com/questions/44571909
复制相似问题