【发布时间】:2016-03-02 19:55:15
【问题描述】:
我试图找到一种方法可以在加载动态上下文菜单(右键单击)时抑制 jstree 中的 changedevent。我知道您可以在上下文菜单中suppress the select_node event,但我需要获取我右键单击的节点的节点 ID。 (因此需要使用select_node)。我知道您可以在定期调用select_node 时suppress that changed event,但我不知道右键单击时该怎么做。我使用上下文菜单select_node 尝试了以下操作,但没有成功:
$(function () {
$('#myTree').jstree({
"core": {
"themes": {
"variant": "small",
"icons": false
}
},
"contextmenu": {
"items": reportMenu(node), //builds context menu based on selected node
},
"plugins": ["contextmenu", "changed"]
});
});
$("#myTree").bind('select_node.jstree', function (event, data) {
// Does not work, changed event still fires.
$("#myTree").jstree().select_node(data.node.id, true);
});
我正在寻找一种可能的替代方案:
- 当上下文菜单调用
select_node时,如何抑制changed事件? - 如何在不调用
select_node事件的情况下获取我右键单击的节点的ID(如果我将上下文菜单设置为'select_node': false,我如何捕获选择节点 )?
【问题讨论】:
-
顺便说一句,为什么不能在
reportMenu函数中获取节点ID 为node.id?
标签: javascript jquery contextmenu jstree