jsTree Contextmenu get selected node id

Dan

Hi I am currently having an issue with the jsTree Context menu. I would like to grab the id of the selected node however I've looked at a number of solutions and none have worked. My code is below.

The function I have which uses tree.get_selected($node) does return an object of the selected node but I'm struggling to access the id parameter of the object. Below I used tree.get_selected($node).id but it says it's undefined but its clearly not when I look at the console.

Can anyone help as to where I'm going wrong?

$("#tree_1").jstree({
    "core" : {
    "themes" : {
        "responsive": false
    },
    // so that create works
    "check_callback" : true,
    'data' : {
        'url' : function (node) {
                if(node.id=='#') {
                    var id = 0; 
                } else {
                    var id = node.id;   
                }
                return 'organisation/getOrganisationLocations/'+id;
            }
        }
    },
    "types" : {
        "default" : {
            "icon" : "fa fa-folder icon-state-warning icon-lg"
        },
        "file" : {
            "icon" : "fa fa-file icon-state-warning icon-lg"
        }
    },
    "state" : { "key" : "demo3" },
    "plugins" : [ "dnd", "state", "types", "contextmenu" ],
    "contextmenu":{         
    "items": function($node) {
            var tree = $("#tree_1").jstree(true);
            return {
                "Create": {
                    "separator_before": false,
                    "separator_after": false,
                    "label": "Create",
                    "action": function (obj) { 
                        $node = tree.create_node($node);
                        tree.edit($node);

                        console.log(tree.get_selected($node).id);
                    }
                },
                "Rename": {
                    "separator_before": false,
                    "separator_after": false,
                    "label": "Rename",
                    "action": function (obj) { 
                        tree.edit($node);
                    }
                },
                "Remove": {
                    "separator_before": false,
                    "separator_after": false,
                    "label": "Remove",
                    "action": function (obj) { 
                        tree.delete_node($node);
                    }
                }
            };
        }
    }
});
AlejoE NQN

This approach worked for me:

$(node).attr('id')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jsTree Contextmenu get selected node id

From Dev

Get the selected Node from a jstree

From Dev

How to get node by ID in Jstree

From Dev

Get Selected Jstree node values JQuery

From Dev

How to get selected node's text in jstree

From Dev

jstree: how to get the id of undetermined state of node

From Dev

jstree: how to get the id of undetermined state of node

From Dev

jsTree: How to *set* opened/selected node by path (not ID)?

From Dev

How to get all the IDs of selected nodes to root node in jsTree?

From Dev

How to get full path of selected node in jstree?(root node to selected node)

From Dev

jstree initial node id

From Dev

Get ContextMenu item ID

From Dev

How to remove child nodes of selected node in jstree?

From Dev

JsTree custom contextmenu in TypeScript

From Dev

PHP Array with JsTree make node selected from a selected array

From Dev

jstree: Select a node in jstree by name attribute rather than id

From Dev

jstree: Select a node in jstree by name attribute rather than id

From Dev

jsTree Get new node AFTER node is created

From Dev

jsTree can't find node by ID

From Dev

jsTree opened node attributes... how to get?

From Dev

jstree contextmenu - how to save changes

From Dev

ObjectListView Treeview Get Selected tree view node Id

From Dev

how to use set_id to rename node_id in jstree?

From Dev

how to use set_id to rename node_id in jstree?

From Dev

ListBox.ContextMenu Get Selected Item via Command

From Dev

ListBox.ContextMenu Get Selected Item via Command

From Dev

Get the id of the selected option

From Dev

Get the id of the selected option

From Dev

Get id of feature selected

Related Related

HotTag

Archive