标签:res span target 分享 ref cti open src href
普通写法:
var twoLevel = data[‘result‘]; //console.log(twoLevel.length); 4 var html = ""; for (var i = 0; i < twoLevel.length; i++) { var threeLevel = twoLevel[i].children; if (threeLevel.length > 0) { html += "<li><a class=‘inactive‘>" + twoLevel[i].displayName + "</a>"; html += "<ul style=‘display: none‘>"; for (var j = 0; j < threeLevel.length; j++) { var fourLevel = threeLevel[j].children; if (fourLevel.length > 0) { html += "<li><a class=‘inactive‘>" + threeLevel[j].displayName + "</a>"; html += "<ul style=‘display: none‘>"; for (var k = 0; k < fourLevel.length; k++) { var fiveLevel = fourLevel[k].children; if (fiveLevel.length > 0) { html += "<li><a class=‘inactive‘>" + fourLevel[k].displayName + "</a>"; html += "<ul style=‘display: none‘>"; for (var w = 0; w < fourLevel.length; w++) { html += "<li><a target=‘iframe‘ href=" + fiveLevel[w].url + ">" + fiveLevel[w].displayName + "</a>"; } html += "</ul>"; } else { html += "<li><a target=‘iframe‘ href=‘" + fourLevel[k].url + "‘>" + fourLevel[k].displayName + "</a>"; } html += "</li>"; } html += "</ul>"; } else { html += "<li><a target=‘iframe‘ href=‘" + threeLevel[j].url + "‘>" + threeLevel[j].displayName + "</a>"; } html += "</li>"; } html += "</ul>"; } else { html += "<li><a target=‘iframe‘ href=‘" + twoLevel[i].url + "‘>" + twoLevel[i].displayName + "</a>"; } html+="</li>"; }
递归写法:
var twoLevel = data[‘result‘]; //console.log(twoLevel.length); 4 var html = ""; function test(childMenu) { for (var i = 0; i < childMenu.length; i++) { var childData = childMenu[i].children; if (childData.length > 0) { html += "<li><a class=‘inactive‘>" + childMenu[i].displayName + "</a>"; html += "<ul style=‘display: none‘>"; test(childData); html += "</ul>"; } else { html += "<li><a target=‘iframe‘ href=‘" + childMenu[i].url + "‘>" + childMenu[i].displayName + "</a>"; } html += "</li>"; } } test(twoLevel);
标签:res span target 分享 ref cti open src href
原文地址:http://www.cnblogs.com/AmbiguousMiao/p/7361845.html