jstree jquery plugin - Get all child and sub child nodes of parent

前端 未结 3 1575
感情败类
感情败类 2021-01-19 03:05

I am using the jsTree jquery plugin

I am trying to fetch all the nodes and sub nodes of a selected parent. But somehow it\'s not working unless I use recursion.

3条回答
  •  情歌与酒
    2021-01-19 03:17

    I found a way to do this. In my case I am using xml as the datasource for the tree. I am binding the open_node event to the jstree in the following manner. Mind it that even though I am using xml, the internal structure is that of html data.

    // jsTree Configuration hash
    var jsTreeConfig = {};
    
    $("#demo1").jstree( jsTreeConfig )
                .bind('open_node.jstree', function( e, data ) {
                    var parentObj = data.rslt.obj; // parent object
                    var jstreeInstance = data.inst; // jstree instance
                    $(data.rslt.obj).find("li").each( function( idx, listItem ) {
                        var child = $(listItem); // child object
                        // do Stuff with child which can be any level of hierarchy depth
                        // ...
                    });
                });
    

提交回复
热议问题