I'm currently loading a modal form when I'm inserting a new node into a jstree using the following code:
$("#structureForm").dialog({
autoOpen: false,
height: 120,
width: 300,
modal: true,
buttons: {
"Create new structure": function() {
$("#structureBuilderTable").jstree("create", /*parent node*/, "inside", title.val(), null, true);
},
"Cancel": function(){
$(this).dialog("close");
}
},
close: function(){
/* do something */
}
})
And then I call the dialog:
var parent = $(e.target).closest('.structureNode');
$("#structureForm").dialog("open");
However, I need to pass the parent node to the dialog, in order to properly create the new node (and for generating the correct id as well). Is there anyway to pass (or piggyback) data to the moda开发者_StackOverflowl form? I tried using:
.data('parent', this)
but didn't find any way to manipulate the 'parent' string to extract the ID.
Any help would be greatly appreciated :-)
Using .data()
should work for you:
$("#structureForm").dialog({
/* snip */
buttons: {
"Create new structure": function() {
var parent = $(this).data("parent");
$("#structureBuilderTable").jstree("create", parent, "inside", title.val(), null, true);
}
}
});
And then calling the dialog:
var parent = $(e.target).closest('.structureNode');
$("#structureForm").data("parent", parent).dialog("open");
精彩评论