jquery optgroup树形循环
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 49,
"MenuName": "样品管理",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 0,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 781,
"MenuName": "请验管理",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 113863,
"MenuName": "添加请验",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 61,
"MenuName": "请验确认",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 63,
"MenuName": "取样确认",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 114158,
"MenuName": "取样分样",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 116768,
"MenuName": "取样异常",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 65,
"MenuName": "性状检测",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 66,
"MenuName": "性状检测审核",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 129383,
"MenuName": "样品进度查询",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 977,
"MenuName": "样品查询",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 21737,
"MenuName": "剩余样品销毁",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 21815,
"MenuName": "剩余样品销毁审核",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 116187,
"MenuName": "录入数据复核",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
},
{
"MenuBigCss": null,
"MenuCss": null,
"ID": 27700,
"MenuName": "ELN数据审核",
"MenuOutPath": null,
"MenuOverPath": null,
"ParentID": 49,
"ShowOrder": 0,
"Discription": null,
"MenuLevel": 0,
"MenuUrlPath": null,
"MenuImg": null,
"Visible_Check": null
}
想要得到的效果就是
<select name="categorys">
<optgroup label="WEB编程">
<option value="2" >PHP</option>
<option value="3" >Ajax</option>
<option value="4" >java</option>
</optgroup>
<optgroup label="WinForm编程">
<option value="6" >VB</option>
<option value="7" >VC</option>
</optgroup>
</select>
父节点ID 节点名称MenuName 子节点ParentID
目前我写法是
$.ajax({
type: "POST",
url: "/UserManag/GetNeoMenu",
//data: "provinceId=" + provinceId,
success: function (jsonData) {
var citys = eval(jsonData);
//alert(citys);
$.each(citys, function (index, menu) {
//alert(menu.MenuName);
if (menu.ParentID == '0') {
$("#sele_menuId").append('<optgroup label="' + menu.MenuName + '">');
if (menu.ID == menu.ParentID) {
$("#sele_menuId").append('<option value="' + menu.ID + '">' + menu.MenuName + '</option>');
$("#sele_menuId").append('</optgroup>');
//return false;
} else {
$("#sele_menuId").append('</optgroup>');
//return false;
}
}
});
$("#sele_menuId").multipleSelect("refresh");
}
});
但效果不行