如何在extjs 4.2中包装表单的提交数据? [英] How to wrap submit data of form in extjs 4.2?
本文介绍了如何在extjs 4.2中包装表单的提交数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在提交了:
method: save
name: Michael
birthday: 1983-02-01
但我需要:
method: save
data[name]: Michael
data[birthday]: 1983-02-01
和字段名称必须类似于 birthday
,而不是 data [birthday]
.
and field name must be like birthday
not data[birthday]
.
推荐答案
假定您正在处理表单提交,而您拥有一个代表该表单的控件:
Assuming that you're handling a form submission where you have a control representing the form:
var formData = form.getFieldValues();
来自Ext.form.Basic.getFieldValues
然后通过ajax提交:
And then submitting via ajax:
Ext.Ajax.request({url: "postlocation.php", method: "POST", data: formData});
如果您不想提交表单,则可以覆盖表单上的按钮以调用模拟提交的过程.
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
});
}
}
});
这篇关于如何在extjs 4.2中包装表单的提交数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文