Extjs optimization (2) general implementation of Form submission _ extjs

Source: Internet
Author: User
This article will show you how to use this code for the next instance. You only need 25-30 lines of original code for 13 lines. If you are interested, please refer to the following: The Code is as follows:


/**
* Submit a form
*/
Function $ postForm (){
If (a. formPanel. getForm (). isValid ()){
Var B = a. scope? A. scope: this;
A. formPanel. getForm (). submit ({
Scope: B,
Url: a. url,
Method: "post ",
Params: a. params,
WaitMsg: "submitting data ...",
Success: function (c, d ){
Ext. ux. Toast. msg ("operation information", "saved successfully! ");
If (a. callback ){
A. callback. call (B, c, d );
}
},
Failure: function (c, d ){
Ext. MessageBox. show ({
Title: "operation information ",
Msg: "An error occurred while saving the information. Please contact the administrator! ",
Buttons: Ext. MessageBox. OK,
Icon: "ext-mb-error"
});
If (a. callback ){
A. callback. call (B );
}
}
});
}
}


To use the modified Code, only 13 lines of original code need 25-30 lines of code. For example:

The Code is as follows:


SaveRecord: function (){
$ PostForm ({
FormPanel: this. formPanel,
Scope: this,
Url: _ ctxPath + "/basedata/saveStudentDepartment. action ",
Params :{},
Callback: function (d, f ){
Var e = Ext. getCmp ("StudentDepartmentGrid ");
If (e! = Null ){
E. getStore (). reload ();
}
B. close ();
}
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.