Getting node ID for jstree when using spearate menu and jstree-grid
My jstree uses jstree-grid, and one of the columns includes an action menu (which is generated by separate code, and all I need to do is apply the class "actionHandler" to generate the menu at runtime). This action menu consists of some extra div's, ul's and li's, which pretty much drowns the click event in HTML code.
What I want to accomplish is the following:
When the admin_new (representing 'new node') choice is clicked, I want to be able to retrieve the ID of the node for which the generated menu was clicked, in order to append this node as a child for the current node.
This is my current code:
jQuery("#structureBuilderTable").jstree({
json_data: {data: testData},
themes: {
theme : "apple",
dots : false,
icons : false
},
plugins: ["json_data", "crrm", "ui", "themes", "grid"],
core: {initially_open: [1]},
grid : {
columns: [
{width: 200, header: "Title"},
{value:"id", width: 50, header: "id"},
{value:"logicalTitle", width: 50, header:"logical title"},
{width: 100, header:"handlinger", cellClass:'actionHandler'},
{value:"resource", width: 200, header:"resource"}
]
}
}).bind("loaded_grid.jstree", function()
{
generateActionMenu("span.actionHandler",{
admin_new: function(e)开发者_如何学运维{
var nodeID = $(e.target).parents(/* Need an unique property*/).data('id');
},
admin_delete: function(e){
/* delete node*/
}, 'admin_open');
});
And this is my dummy JSON:
var testData = [
{
data: "Seksjon1",
attr: {id:"1", logicalTitle:"r2d2", resource:"videofile"},
children: [
{
data: "Flersvar",
attr: {id:"2", logicalTitle:"c3p0", resource:"checkbox"}
},
{
data: "Flashtest",
attr: {id:"3", logicalTitle:"d2r2", resource:"flash"}
}
]
}];
The main problem is that since no node is selected, I don't have access to any jstree specific events (giving access to the data object, which could've potentially solved the problem).
So, the question is basically: How can I retrieve relevant node information without directly manipulating the tree?
Any help would be greatly appreciated! (Sorry for the wall of text :p)
The solution has been posted: see my comment.
精彩评论