Найти только текущее содержимое диалога jQueryUI в обработчике открытия диалога - PullRequest
0 голосов
/ 16 января 2019

У меня есть приложение, в котором одновременно могут быть открыты несколько диалогов jQueryUI.

Моя проблема в том, что я не могу понять, как найти только текущие элементы диалогов в открытом обработчике диалога.

Я пробовал $ (this), ui, ui.dialog и некоторые другие вещи, но безрезультатно.

$("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
    .dialog({
        closeOnEscape: false,
        open: function (event, ui) {
            /* 
               What can I use to filter the two selectors below
               so that they only affect the current dialogs contents?
            */
            $(".ui-dialog-titlebar-close", ui.dialog | ui).hide();
            $('.ui-dialog-buttonpane', ui.dialog | ui).find('button').each(function (id, el) {
                /* This cycles through all buttons on all dialogs */
                debugger;
            });
        },
        buttons: {
            "Button 1": function () { doStuff; },
            "Button 2": function () { doStuff; },
            "Button 3": function () { doStuff; }
        }
    });

1 Ответ

0 голосов
/ 19 января 2019

Решением для меня было обратиться к родительскому элементу цели события.

например, event.target.parentElement

$("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
    .dialog({
        closeOnEscape: false,
        open: function (event, ui) {
            /* Hide the close button of the dialog your are loading */
            $(".ui-dialog-titlebar-close", event.target.parentElement).hide();

            /* Cycle through only the buttons belonging to the current dialog */
            $('.ui-dialog-buttonpane', event.target.parentElement).find('button').each(function (id, el) {
                debugger;
            });
        },
        buttons: {
            "Button 1": function () { doStuff; },
            "Button 2": function () { doStuff; },
            "Button 3": function () { doStuff; }
        }
    });
...