EXt向astruts2 action导入数据,有完整代码
Ext.onReady(function() {
Ext.QuickTips.init();
// 输入验证框不通过是时,消息提示方式有四种:qtip,title,under,side
Ext.form.Field.prototype.msgTarget = 'under';
var requiredMark = '<span style="color:red">*</span>';
var isPersonNameOK = true; // 先定义个全局变量
var IsExsit = false;// 此变量一定要在方法外面定义
function ReturnValue(ok) {// 此方法必须放CheckUserName里面。
IsExsit = ok;
}
function checkName() { // 检查用户名是否存在
var username = Ext.get('parts.partsname').dom.value;
Ext.Ajax.request({
url : 'CheckPartsAction',
params : {
name : username
},
success : function(response, options) {
var data = Ext.util.JSON.decode(response.responseText);
if (data.success == true) {
ReturnValue(true);
} else {
ReturnValue(false);// 不能在success里面直接return
}
}
});
return IsExsit;
}
var simple = new Ext.FormPanel({
frame : true,
layout : "form",
title : "添加配件信息",
// monitorValid : true,
labelWidth : 70,
renderTo : "form",
xtype : 'fieldset',
collapsible : true,
labelAlign : 'right',
method : 'post',
autoHeight : true,
width : 330,
defaultType : 'textfield',
defaults : {
width : 200
},
items : [{
xtype : "textfield",
fieldLabel : requiredMark+ '配件名称编码',
name : 'parts.partsnameid',
allowBlank : false
}, {
xtype : "textfield",
fieldLabel : requiredMark + '配件名称',
name : 'parts.partsname',
allowBlank : false,
//validator : CheckName,
validatorEvent : 'blur',
invalidText : "配件名称已经存在",
emptyText : "请输入配件名称",
validator : function(thisText) {
if (thisText != '') {
Ext.Ajax.request({
url : 'CheckPartsAction.action',
method : 'post',
params : {
name : thisText
},
success : function(response,
options) {
var data = Ext.util.JSON
.decode(response.responseText);//获取action里的rs json
if (data.success == true) {
isPersonNameOK = false;
Ext
.getCmp('parts.partsname')
.markInvalid('配件名称已经存在');
} else {
isPersonNameOK = true;
Ext.getCmp('parts.partsname')
.clearInvalid();
}
}
});
}
return isPersonNameOK;
}
},{
xtype:"textfield",
fieldLabel : requiredMark+'型号名称',
name:'parts.xinghaoname',
allowBlank:false
},{
xtype:"textfield",
fieldLabel : requiredMark+'配件型号',
name:'parts.partsxinghao',
allowBlank:false
},{
xtype:"textfield",
fieldLabel : requiredMark+'最大编号',
name:'parts.mingpaiid',
allowBlank:false
},{
xtype:"textfield",
fieldLabel : requiredMark+'配件工程师',
name:'parts.partsengineer',
allowBlank:false
},{
xtype:"textfield",
fieldLabel : requiredMark+'出厂日期',
name:'parts.outdate',
allowBlank:false
},{
xtype:"textfield",
fieldLabel : requiredMark+'注册日期',
name:'parts.registertime',
allowBlank:false
},{
xtype:"textfield",
fieldLabel : requiredMark+'库名称',
name:'parts.libraryname',
allowBlank:false
}],
// 增加按钮
buttons : [{
text : '确定',
handler : function() {
if (!simple.getForm().isValid())
return;
simple.getForm().submit({
waitMsg : "正在提交数据……",
waitTitle : "提示",
url : "AddPartsAction.action",
method : "post",
success : function(form, action) {
Ext.Msg.alert("提示",
action.result.message);
},
failure : function(form, action) {
Ext.Msg.alert("提示",
action.result.message);
}
});
}
}, {
text : '取消',
handler : function() {
simple.getForm().reset();
}
}]
}
);
}
);