我的要求之一是加载(通过 ajax on demand)在 jstree 上选择的节点的所有子节点,并返回其下叶节点的所有锚元素 id。我可以通过将所选节点传递给 open_all 方法并在 open_all 事件中返回前导节点的 ID 来做到这一点。但是,我的问题是,当所选的是除根以外的非叶节点时,open_all事件会发射两次。如果所选节点是根节点或叶节点,它可以正常工作。任何帮助是极大的赞赏。
$tree
.bind("loaded.jstree", function(event, data) {
//alert("Tree loaded");
})
.bind("select_node.jstree", function(event, data) {
data.inst.open_all(data.rslt.obj, true);
})
.bind("check_node.jstree", function(event, data) {
//checkboxes are enabled on some pages
data.inst.open_all(data.rslt.obj, true);
})
.bind("open_all.jstree", function(event, data) {
//get all ids of leaf nodes under selected node if selected node is
//non-leaf node. If selected node is a leaf node return it's id.
//alert(leaf_ids);
//**Here is my problem:** The alert box pops up twice if
//open_all was passed a non-leaf node other than root.The first time
//ids are empty but the second time I see the ids.
})
.jstree({
"plugins": plugins_include,
"core": core_options,
"html_data": html_data,
"themes": {
"theme": "classic",
"dots": false,
"icons": false
},
"strings": { loading: "Loading..." },
"checkbox": {
"override_ui": true
},
"ui": { "select_multiple_modifier": false }
});