layui动态渲染生成select的option值

 1 //展示下拉框
 2     function showCategory(data, count) {
 3         $(data).each(function (i, n) {
 4           //  console.log(n);
 5             var t = "";
 6             for (var j = 0; j < count; ++j) {
 7                 t += "&nbsp;&nbsp;&nbsp";
 8             }
 9             if (n.children.length > 0) {
10                 $("#toolType").append("<option value='" + n.id + "' style='font-weight: bold;'>" + t + n.categoryName + "</option>");
11                 showCategory(n.children, count + 1)
12             } else {
13                 $("#toolType").append("<option value='" + n.id + "'>" + t + n.categoryName + "</option>");
14             }
15         });
16         form.render('select');
17     }
18     $("#toolType").append("<option value=''>请选择脚本类型</option>");
19     $.get("/cd/tool/category/tree.afca", {}, function (data) {
20         showCategory(data.data, 0);
21         form.render('select');
22     }, "json");

猜你喜欢

转载自www.cnblogs.com/yangguoe/p/8954310.html