对象未传递给jQuery Dialog OnSubmit处理程序

时间:2015-05-04 08:32:16

标签: javascript jquery jquery-ui

我有以下HTML:

<div id="referenceResolverDialog" title="Resolve IDs">
    <p>Please fill in a comma separated list of IDs.</p>
    <form>
        <fieldset>
            <textarea name="referenceResolverTextArea" id="referenceResolverTextArea" rows="6" cols="54"></textarea>
        </fieldset>
    </form>
</div>

我创建了jQuery对话框,如下所示:

var configParams = {
    // some config properties
    textAreaSelector: '#referenceResolverTextArea',
    // some other config properties
}

var form, dialog;

dialog = $(configParams.dialogSelector).dialog({
    autoOpen: false,
    height: 220,
    width: 350,
    modal: true,
    buttons: {
        "Resolve": ResolveDialogData,
        Cancel: function () {
            dialog.dialog("close");
        }
    },
    close: function () {
        form[0].reset();
        dialog.dialog("close");
    }
});

form = dialog.find("form").on("submit", function (event) {
    event.preventDefault();
    ResolveDialogData(configParams);
});

问题是configParams作为新对象传递,而不是我已经拥有的对象。在ResolveDialogData()方法中,我有以下内容:

function ResolveDialogData(configParams) {
    alert(configParams); // returns [object Object]
    alert(configParams.textAreaSelector); // returns undefined
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

如果您从“解决”按钮进入回调,则configParams参数将代表对话框传递的Event对象。

更改

buttons: {
        "Resolve": ResolveDialogData,
        Cancel: function () {
            dialog.dialog("close");
        }
    },

buttons: {
        "Resolve": function(e) { // e is the object you were ending up with before 
            ResolveDialogData(configParams); 
        },
        Cancel: function () {
            dialog.dialog("close");
        }
    },