我試圖找到一種方法,我可以在加載動態上下文菜單(右鍵單擊)時在jstree中抑制changed
事件。我知道你可以在上下文菜單中輸入suppress the select_node event,但我需要獲取我正確點擊的節點的節點ID。 (因此需要使用select_node
)。我知道當您定期撥打select_node
時,您可以撥打suppress that changed event,但我不確定如何在右鍵單擊時執行此操作。我試圖通過上下文菜單select_node
以下,但沒有奏效:Jstree上下文菜單supress在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);
});
我在尋找可能的替代方案之一:
- 我怎樣才能抑制
changed
事件當背景菜單調用select_node
? - 如何在不調用
select_node
事件(即如果將我的上下文菜單設置爲'select_node': false
,如何捕獲選擇節點)的情況下右鍵點擊節點的id?
順便說一句,爲什麼你不能在你的'reportMenu'函數中得到節點id作爲'node.id'? –