Im trying to find a way I can suppress the changed
event in jstree when loading a dynamic context menu (right click). I'm aware that you can suppress the select_node event in the context menu but I need to get the node id of the node that I am right clicking on. (and therefore need to use the select_node
). I know that you can suppress that changed event when calling select_node
regularly, but I'm not sure how to do it when right clicking. I tried the following with the context menu select_node
, but it did not work:
$(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);
});
I'm looking for one of the possible alternatives:
- How can I suppress the
changed
event when the context menu callsselect_node
? - How can I get the id of the node I am right clicking on without calling the
select_node
event (i.e. If I set my contextmenu to'select_node': false
, how can I capture the select node)?
Im trying to find a way I can suppress the changed
event in jstree when loading a dynamic context menu (right click). I'm aware that you can suppress the select_node event in the context menu but I need to get the node id of the node that I am right clicking on. (and therefore need to use the select_node
). I know that you can suppress that changed event when calling select_node
regularly, but I'm not sure how to do it when right clicking. I tried the following with the context menu select_node
, but it did not work:
$(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);
});
I'm looking for one of the possible alternatives:
- How can I suppress the
changed
event when the context menu callsselect_node
? - How can I get the id of the node I am right clicking on without calling the
select_node
event (i.e. If I set my contextmenu to'select_node': false
, how can I capture the select node)?
-
1
By the way, why can't you get the node id as
node.id
inside yourreportMenu
function ? – Nikolay Ermakov Commented Mar 2, 2016 at 22:49
1 Answer
Reset to default 6Finally, I think you can get what you want changing your code a little.
Check demo - codepen.
$('#myTree')
.jstree({
'core': {
'data': ...
},
'plugins': ["contextmenu"],
'contextmenu': {
'select_node': false,
'items': reportMenu
}
});
function reportMenu(node) {
// access node as: node.id);
// build your menu depending on node id
return {
createItem: {
"label": "Create New Branch",
"action": function(obj) {
this.create(obj);
alert(obj.text())
},
"_class": "class"
},
renameItem: {
"label": "Rename Branch",
"action": function(obj) { this.rename(obj); }
},
deleteItem: {
"label": "Remove Branch",
"action": function(obj) { this.remove(obj); }
}
};
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744808696a4594934.html
评论列表(0条)