如何在extjs 4.2中包装表单的提交数据?

问题描述 投票:1回答:1

我现在提交:

method: save
name: Michael
birthday: 1983-02-01

但是我需要:

method: save
data[name]: Michael
data[birthday]: 1983-02-01

和字段名称必须像birthday而不是data[birthday]

forms extjs submit
1个回答
5
投票

假设您正在处理表单提交,其中您有一个表示该表单的控件:

var formData = form.getFieldValues();

From Ext.form.Basic.getFieldValues

然后通过ajax提交:

Ext.Ajax.request({url: "postlocation.php", method: "POST", data: formData});

From Ext.Ajax.request

如果您不想提交表单,可以覆盖表单上的按钮以调用模拟提交的进程。

// 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
             });
         }
     }
});
© www.soinside.com 2019 - 2024. All rights reserved.