问题
I have now by submit:
method: save
name: Michael
birthday: 1983-02-01
but I need:
method: save
data[name]: Michael
data[birthday]: 1983-02-01
and field name must be like birthday
not data[birthday]
.
回答1:
Assuming that you're handling a form submission where you have a control representing the form:
var formData = form.getFieldValues();
From Ext.form.Basic.getFieldValues
And then submitting via ajax:
Ext.Ajax.request({url: "postlocation.php", method: "POST", data: formData});
From Ext.Ajax.request
If you don't want to submit your form, you can override a button on the form to invoke a process that simulates a submission.
// form def up here
buttons: [
text: "Pseudo-Submit",
id: "altsubmitbuttonthing"
]
In your controller (or an event handler for the button:
this.control({
"button[id=altsubmitbuttonthing]": {
click: function (control) {
var form = control.up("form"), // <- now you have your form and you can do whatever you want with it's data.
formData = form.getFieldValues(),
preparedData = {};
formData.theDateField = new Date(data.theDateField);
formData.theIntField = parseInt(data.theIntField, 10);
preparedData.data.birthday = formData.birthday;
preparedData.data.name = formData.name;
Ext.Ajax.request({
url: "/submissions",
method: "POST",
type: "json",
data: preparedData
});
}
}
});
来源:https://stackoverflow.com/questions/16273286/how-to-wrap-submit-data-of-form-in-extjs-4-2