用户登录
用户注册

分享至

Extjs优化(二)Form表单提交通用实现

  • 作者: 像个蝴蝶
  • 来源: 51数据库
  • 2021-08-01
复制代码 代码如下:

/**
* 提交表单
*/
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);
}
}
});
}
}

使用改代码只需要13行代码 原始需要25-30行代码搞定 ,示例:
复制代码 代码如下:

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();
}
});
软件
前端设计
程序设计
Java相关