使用layui tree 获取已选中的数据的id
/**
* 获取layui tree模块的选中的所有id
* @param arr 选中数据,树结构
* @returns {string|*}
*/
function getLayuiTreeIds(arr, list) {
if (!list) list = [];
for (const item of arr) {
list.push(item.id);
let subs = item.children;
if (subs && subs.length > 0) {
getLayuiTreeIds(subs, list);
}
}
return list.join(','); //以逗号拼接返回
}
// 调用
let menus = getLayuiTreeIds(tree.getChecked('treeId'));
// menus为 123,124,125