父节点检查jstree [英] Parent node check in jstree
本文介绍了父节点检查jstree的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的jstree:
I have a jstree as shown below:
$('#FolderTree').jstree({
'core': {
'data': [
{
'text': 'Claim key',
'state': {
'opened': false,
'selected': false
},
'children': claimKeys
},
{
'text': 'Client',
'state': {
'opened': false,
'selected': false
},
'children': clients
}
]
},
"plugins": ["checkbox"]
});
对于复选框的点击事件,我使用下面的jquery:
For click event of checkbox I'm using the below jquery :
$('#FolderTree').on("select_node.jstree", function (e, data) {
var checkedValue = data.node.text;
});
但我想首先确定我点击的复选框是父节点还是子节点。我怎么能这样做?
But I want to first determine if the checkbox I've clicked is parent node or child node..How can I do that??
推荐答案
你可以使用这段代码:
$('#FolderTree').on("select_node.jstree", function (e, data) {
var checkedValue = data.node.text;
var isParent = data.instance.is_parent();
// you can also use is_leaf() to check the opposite
});
is_parent
会告诉你节点是否有任何孩子, is_leaf
会告诉你它是否是一个叶子节点(如果它没有孩子) - 使用其中一个。
is_parent
will tell you if the node has any children, is_leaf
will tell you if it is a leaf node (if it has no children) - use one or the other.
如果您需要检查节点是否是根节点,您可以使用:
var isRoot =(data。 node.parents.length === 1)
If you need to check if a node is a root node you can use:
var isRoot = (data.node.parents.length === 1)
这篇关于父节点检查jstree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文