How to wrap submit data of form in extjs 4.2?

人走茶凉 提交于 2021-02-10 20:49:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!