开发者

Pass data to modal forms (JQuery UI)

开发者 https://www.devze.com 2023-03-16 17:05 出处:网络
I\'m currently loading a modal form when I\'m inserting a new node into a jstree using the following code:

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消