0

我很难使用 JQM 的新 Alpha 版本不显示嵌套弹出窗口。例如,我正在显示一个用户应该填写的弹出表单,如果服务器端验证失败,我想显示一个错误弹出窗口。我发现没有显示错误弹出窗口。我怀疑它显示在原始弹出窗口下方。

function bindSongWriterInvite() {

    // Bind the click event of the invite button
    $("#invite-songwriter").click(function () {
        $("#songwriter-invite-popup").popup("open");
    });

    // Bind the invitation click event of the invite modal
    $("#songwriter-invite-invite").click(function () {
        if ($('#songwriter-invite').valid()) {
            $('#songwriter-invite-popup').popup('close');
            $.ajax({
                type: 'POST',
                async: true,
                url: '/songwriter/jsoncreate',
                data: $('#songwriter-invite').serialize() + "&songName=" + $("#Song_Title").val(),
                success: function (response) {
                    if (response.state != "success") {
                        alert("Should be showing error dialog");
                        mobileBindErrorDialog(response.message);
                    }
                    else {
                        mobileBindErrorDialog("Success!");
                    }
                },
                failure: function () {
                    mobileBindErrorDialog("Failure!");
                },
                dataType: 'json'
            });
        }
    });

    // Bind the cancel click event of the invite modal
    $("#songwriter-invite-cancel").click(function () {
        $("#songwriter-invite-popup").popup("close");
    });
}

function mobileBindErrorDialog(errorMessage) {
    // Close all open popups.  This is a work around as the JQM Alpha does not
    // open new popups in front of all other popups.
    var error = $("<div></div>").append("<p>" + errorMessage + "</p>")
                                .popup();
    $(error).popup("open");
}

因此,您可以看到我尝试显示错误对话框,无论 ajax 发布是成功还是失败。它只是永远不会出现。

有人有什么想法吗?

麦克风

4

1 回答 1

0

我找到了解决办法!

我在 bindErrorPopup 函数上设置了一个延迟,以等待弹出关闭动画完成。

function mobileBindErrorDialog(errorMessage, delay) {
    var error = $("<div></div>").attr({
        'data-rel': "popup",
        'data-theme': "a"
    });

    $(error).append("<p>" + errorMessage + "</p>")
            .popup({
                overlayTheme: "a",
                positionTo: "window",
                theme: "a"
            });

    setTimeout(function () {
        $(error).popup("open");
    }, delay);
}

效果很棒!

于 2012-09-03T23:57:20.920 回答