問題描述
我正在使用 jsTree jquery 插件
我正在嘗試獲取選定父節(jié)點的所有節(jié)點和子節(jié)點.但不知何故,除非我使用遞歸,否則它不起作用.jsTree 有沒有更好的方法?
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. Is there a better way inherent to jsTree?
推薦答案
我找到了一種方法.就我而言,我使用 xml 作為樹的數(shù)據(jù)源.我通過以下方式將 open_node 事件綁定到 jstree.請注意,即使我使用的是 xml,內(nèi)部結(jié)構(gòu)也是 html 數(shù)據(jù)的結(jié)構(gòu).
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
// ...
});
});
這篇關(guān)于jstree jquery插件 - 獲取父節(jié)點的所有子節(jié)點和子子節(jié)點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!