我现在通过提交:
method: save
name: Michael
birthday: 1983-02-01
但是我需要:
method: save
data[name]: Michael
data[birthday]: 1983-02-01
并且字段名称必须像birthday
not data[birthday]
。
假设您正在处理一个表单提交,其中您有一个表示表单的控件:
var formData = form.getFieldValues();
来自 Ext.form.Basic.getFieldValues
然后通过ajax提交:
Ext.Ajax.request({url: "postlocation.php", method: "POST", data: formData});
如果您不想提交表单,您可以覆盖表单上的按钮来调用模拟提交的过程。
// form def up here
buttons: [
text: "Pseudo-Submit",
id: "altsubmitbuttonthing"
]
在您的控制器(或按钮的事件处理程序中:
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
});
}
}
});