Home > Article > Web Front-end > Extjs Optimization (2) Universal Implementation of Form Submission
/** * 提交表单 */ function $postForm(a) { 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: "正在提交数据...", success: function(c, d) { Ext.ux.Toast.msg("操作信息", "成功信息保存!"); if (a.callback) { a.callback.call(b, c, d); } }, failure: function(c, d) { Ext.MessageBox.show({ title: "操作信息", msg: "信息保存出错,请联系管理员!", buttons: Ext.MessageBox.OK, icon: "ext-mb-error" }); if (a.callback) { a.callback.call(b); } } }); } }
It only takes 13 lines of code to use the modified code. The original requires 25-30 lines of code to complete. Example:
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(); } });
For more Extjs optimization (2) Form form submission universal implementation related articles, please pay attention to the PHP Chinese website!