【发布时间】:2019-02-04 15:00:49
【问题描述】:
我需要能够获取子节点 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"}]}]
我需要获取 L1712、L1743 等 IDS。
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... 部分的节点?我需要获取它们,以便与页面的另一部分进行交互。
【问题讨论】:
-
1.使用
$.getJSON从服务器获取数据 2.从对象中获取ID,3.使用对象构建树
标签: javascript jstree