1. 程式人生 > 實用技巧 >Layui 獲取樹全部選中的節點ID

Layui 獲取樹全部選中的節點ID

話不多說直接上程式碼

        //監聽授權按鈕
        form.on('submit(Authorization)', function (data) {
            var userid = document.getElementById("UserId").value;
            var checkedData = tree.getChecked('ActorTreeid'); //獲取選中節點的資料
            var nodeIds = new Array();
            nodeIds = getCheckedId(checkedData);
            
var ActorTreeid = nodeIds;//JSON.stringify(nodeIds) $.ajax({ type: 'POST', url: '../handler/User_Actor.ashx', data: { "userid": userid, "ActorTreeid": ActorTreeid }, success: function (date) { var result = date;
if (result == "1" || result == "2") { layer.msg("授權成功!", { icon: 6 }); } else { layer.msg("授權失敗!" + result, { icon: 5 }); } }, dataType:
"json", error: function (err) { layer.msg("授權失敗!" + err, { icon: 5 }); } }); return false; }); //獲取所有選中的節點id function getCheckedId(data) { var id = ""; $.each(data, function (index, item) { if (id != "") { id = id + "$" + item.id; } else { id = item.id; } //item 沒有children屬性 if (item.children != null) { var i = getCheckedId(item.children); if (i != "") { id = id + "$" + i; } } }); return id; }