![](/img/trans.png)
[英]jsTree : How to get IDs of selected nodes to root node in jsTree?
[英]How to get all the IDs of selected nodes to root node in jsTree?
如何將選定節點的ID獲取到jsTree中的根節點?
假設F和D是選定的節點,我想獲取所有id包括ABCDF
以下代碼將僅返回立即選擇的ID D和F
var getMenuIds = function(){
var menuIds = $("#menu-tree").jstree("get_checked");
window.alert(menuIds.join(","));
$('#menuIds').val(menuIds.join(","));
}
有什么方法可以獲取所有父節點ID,即“選定節點”到根節點嗎?
調用get_path獲取到每個選定節點的路徑。
就像是:
var tree = $("#menu-tree");
var menuIds = tree.jstree("get_checked");
var paths = menuIds.map(function (id) { return tree.jstree("get_path", id); });
// remove duplicates
var selected = [];
var uniq = {};
paths.forEach(function (path) {
path.forEach(function (id) {
if (!uniq[id]) {
uniq[id] = true;
selected.push(id);
}
});
});
window.alert(selected.join(","));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.