Parent node check in jstree

…衆ロ難τιáo~ 提交于 2019-12-08 05:34:13

问题


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"]
        });

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??


回答1:


You can use this code:

$('#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 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.

If you need to check if a node is a root node you can use:
var isRoot = (data.node.parents.length === 1)



来源:https://stackoverflow.com/questions/30782213/parent-node-check-in-jstree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!