首页 > 代码库 > 递归2
递归2
包含深度(deep)的递归:
// tree list
function tree_list_dialog(datalist, deep) {
var html = ‘‘;
$.each(datalist, function (index, data) {
var html_i_list_before = ‘<i class="list_before_span"></i>‘;
html += ‘<ul class="ul1">‘;
for (var j = 0; j < deep; j++) {
html_i_list_before += ‘<i class="list_before_span"></i>‘
}
html += ‘<li class="left_1" cussortid = "‘ + data["id"] + ‘">‘ + html_i_list_before + ‘<span class="icon_open change_ba"></span><span class="icon_file"></span><span class="list_msg">‘ + data[‘name‘] + ‘</span></li>‘;
if (data[‘children‘] && data[‘children‘].length > 0) {
html += tree_list_dialog(data[‘children‘], deep + 1);
}
html += ‘</li>‘;
html += ‘</ul>‘
});
return html
}
递归2