【发布时间】:2018-11-23 06:33:23
【问题描述】:
我正在从远程服务器请求数据,并以 json 格式返回:
[
{"id":"1", "parent": "#", "text" : "Parent1"},
{"id":"2", "parent": 1, "text" : "Child1"}
{"id":"3", "parent": 2, "text" : "Child12"}
{"id":"4", "parent": 1, "text" : "Child2"}
{"id":"5", "parent": 1, "text" : "Child3"}
{"id":"6", "parent": 4, "text" : "Child21"}
]
我想检查所选节点是否是父节点。我使用此代码:
$('#treeview').on("select_node.jstree", function (e, data) {
var isParent = data.instance.is_parent();
alert(isParent)
});
即使我点击 PARENT,它也总是返回 false。
我在这里错过了什么?
更新
这就是我解决问题的方法。但我仍然想知道为什么is_parent() 和is_leaf() 方法不起作用
var isParent = (data.node.children.length > 0);
【问题讨论】:
-
@TamilSelvanC 我之前检查过链接,但使用
var isParent = data.instance.is_parent(); alert(isParent)并不能解决问题 -
嗨,我更新了我的答案。请检查
-
我明白了。谢谢
标签: javascript json jstree