2015-05-04 58 views
0

我有以下HTML:对象不会传递到jQuery的对话框onsubmit处理

<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

如果您从“解决”按钮中触击该回调,则您的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"); 
     } 
    }, 
+0

完美谢谢!我的假设是它应该在onsubmit表单上配置。 –