json菜单树过滤器

编程

递归实现json菜单树过滤,过滤到匹配节点并保留其父节点

//递归过滤节点

function nodeFilter(menuList, fiterName) {

var reg = new RegExp(fiterName);

var retMenuList = new Array();

if (menuList && menuList.length > 0) {

for (var c of menuList) {

if (c.subModules) {

c.subModules = nodeFilter(c.subModules, fiterName);

}

if (c.thirdModules) {

c.thirdModules = nodeFilter(c.thirdModules, fiterName);

}

if ((c.subModules && c.subModules.length > 0)

|| (c.thirdModules && c.thirdModules.length > 0)

|| isMatch(c, reg)) {

retMenuList.push(c);

}

}

}

return retMenuList;

}

function isMatch(menu, reg) {

return menu.heading.match(reg)

|| pinyin.getFullChars(menu.heading).toLowerCase().match(reg)

|| pinyin.getCamelChars(menu.heading).toLowerCase().match(reg);

}

 

以上是 json菜单树过滤器 的全部内容, 来源链接: utcz.com/z/510831.html

回到顶部