[英]Get Child Node IDs in JSTree
我需要能夠獲得子節點ID。 我的JS樹在加載時已完全擴展,但是我無法獲得子節點,因為它似乎在一段時間后加載了它們。
通過AJAX檢索示例JSON:
[{"id":"L2","text":"L2","state": {"opened":true},"children":[{"id":"L1711","state":{"opened":true},"text":"cat"},{"id":"L1712","state":{"opened":true},"text":"dog"},{"id":"L1743","state":{"opened":true},"text":"bird"}]}]
我需要獲取IDS,例如L1712,L1743等。
JS:
if ($('#features-tree').is(':empty')) {
$('#features-tree').jstree({
'core': {
'themes': {
'name': 'proton',
'icons': false
},
'data': {
'url': function (node) {
return 'retrieveNodes?imageId=' + _this.imageId;
},
'data': function (node) {
return { 'id': node.id };
},
}
},
});
但是,如果我執行以下控制台日志:
console.log($('div#features-tree > ul > li').html());
我只是回來:
<i class="jstree-icon jstree-ocl"></i><a class="jstree-anchor" href="#"><i class="jstree-icon jstree-themeicon-hidden"></i>Loading ...</a>
如何獲得替換“ Loading...
部分的節點? 我需要獲取它們,以便可以與頁面的另一部分進行交互。
您可以直接通過流程輸入json獲取子級ID列表
let a=[{"id":"L2","text":"L2","state": {"opened":true},"children":[{"id":"L1711","state":{"opened":true},"text":"cat"},{"id":"L1712","state":{"opened":true},"text":"dog"},{"id":"L1743","state":{"opened":true},"text":"bird"}]}]; let r= a.flatMap(x=>x.children.map(y=>y.id)); console.log(r);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.