首页 > 代码库 > Ext js form表单的提交
Ext js form表单的提交
//定义的文本框
var GangKouCode = {
xtype: ‘textfield‘,
name: ‘PORTCODE‘,
id: ‘PORTCODE‘,
allowBlank: false,
emptyText: ‘请输入编号‘,
blankText: ‘请输入编号‘,
fieldLabel: ‘港口编号‘,
labelAlign: ‘right‘,
labelWidth: 60,
width: 150,
autoFitErrors: true,
msgTarget: ‘side‘
}
GangKouName = {
xtype: ‘textfield‘,
name: ‘PORTNAME‘,
id: ‘PORTNAME‘,
allowBlank: false,
blankText: ‘请输入名称‘,
emptyText: ‘请输入名称‘,
fieldLabel: ‘港口名称‘,
labelAlign: ‘right‘,
msgTarget: ‘side‘,
labelWidth: 60
}
//这个是个特殊的 是ComboBox
Ext.regModel(‘Country‘, { fields: [‘CNADDNAME‘, ‘ID‘] });
CountryStore = new Ext.data.JsonStore({
model: ‘Country‘,
proxy: new Ext.data.HttpProxy(
{
type: ‘ajax‘,
url: ‘/FL_Price/JiChuManage/Service.aspx?action=SelectCountry‘,
reader: new Ext.data.JsonReader({
model: ‘Country‘,
root: ‘rows‘
})
})
});
var CountryName = new Ext.form.ComboBox({
store: CountryStore,
fieldLabel: ‘所属国家‘,
labelAlign: ‘right‘,
labelWidth: 60,
queryParam: ‘name‘,
name: ‘COUNTRYNAME‘,
id: ‘COUNTRYNAME‘,
allowBlank: false,
blankText: ‘请输入国家名称‘,
emptyText: ‘请输入国家名称‘,
queryMode: ‘remote‘,
editable: true,
hideTrigger: true,
msgTarget: ‘side‘,
triggerAction: ‘all‘,
hiddenName: ‘ID‘,
displayField: ‘CNADDNAME‘,
valueField: ‘ID‘,
// pageSize: 8,
minChars: 1,
forceSelection: true,
listConfig: {
loadingText: ‘正在加载...‘,
maxHeight: 500
}
});
var HangXian = {
xtype: ‘textfield‘,
name: ‘VOYAGENAME‘,
id: ‘VOYAGENAME‘,
allowBlank: false,
blankText: ‘请选择航线‘,
fieldLabel: ‘所属航线‘,
labelAlign: ‘right‘,
msgTarget: ‘side‘,
labelWidth: 60,
listeners: {
focus: function () {
var win = showhangxianwin();
win.show();
}
}
};
//这是布局
panel = new Ext.form.Panel({
// title: ‘港口编辑‘,
region: ‘north‘,
height: 150,
layout: ‘form‘,
items: [
{ layout: ‘column‘, bodyStyle: ‘border:0‘,
items: [
{ columnWidth: .3, layout: ‘form‘, bodyStyle: ‘border:0‘, items: [GangKouCode] },
{ columnWidth: .3, layout: ‘form‘, bodyStyle: ‘border:0‘, items: [GangKouName] }
]
},
{ layout: ‘column‘, bodyStyle: ‘border:0‘,
items: [
{ columnWidth: .3, layout: ‘form‘, bodyStyle: ‘border:0‘, items: [CountryName] },
{ columnWidth: .3, layout: ‘form‘, bodyStyle: ‘border:0‘, items: [HangXian] }
]
},
{ layout: ‘column‘, bodyStyle: ‘border:0‘,
items: [
{ columnWidth: .6, layout: ‘form‘, bodyStyle: ‘border:0‘, items: [Description] }
]
}
]
});
//第一个的if 是验证
if (panel.getForm().isValid()) {
var Supplier = Ext.encode(Ext.pluck(GKCodeStore.data.items, ‘data‘));
var action = panel.getForm().findField(‘ID‘).getValue() ? "update" : "create";
//这些是获取是文本框的值
var ID = panel.getForm().findField(‘ID‘).getValue();
var VOYAGEID = panel.getForm().findField(‘VOYAGEID‘).getValue();
var VOYAGENAME = panel.getForm().findField(‘VOYAGENAME‘).getValue();
var PORTCODE = panel.getForm().findField(‘PORTCODE‘).getValue();
var PORTNAME = panel.getForm().findField(‘PORTNAME‘).getValue();
var DESCRIPTION = panel.getForm().findField(‘DESCRIPTION‘).getValue();
//获取ComboBox的值 它有两个值
var COUNTRYNAME = CountryName.getRawValue();
var COUNTRYID = CountryName.getValue();//隐藏值
var requestConfig = {
url: "GangKouList2.aspx?action=" + action,
//数据是这种格式的话 后台可以直接转为对象
params: { obj: "{ID:‘" + ID + "‘, VOYAGEID:‘" + VOYAGEID + "‘, VOYAGENAME:‘" + VOYAGENAME + "‘, PORTCODE:‘" + PORTCODE + "‘, PORTNAME:‘" + PORTNAME + "‘, DESCRIPTION:‘" + DESCRIPTION + "‘, COUNTRYNAME:‘" + COUNTRYNAME + "‘, COUNTRYID:‘" + COUNTRYID + "‘}", Supplier: Supplier },
//回调函数
callback: function (option, success, response) {
store.reload();
win1.close();
}
}
//发送异步
Ext.Ajax.request(requestConfig);
}
保存后台 ent = JsonHelper.GetObject<S_VOYAGE_PORT>(obj);
//修改 加载数据
function Update(UpdateID) {
if (UpdateID !=null) {
panel.getForm().load({
url: ‘GangKouList2.aspx?action=SelectEdit‘,
params: { UpdateID: UpdateID },
method: ‘POST‘, //请求方式
success: function (form, action) {
var Country1 = new Country({ ID: action.result.data.COUNTRYID, CNADDNAME: action.result.data.COUNTRYNAME });
CountryName.setValue(Country1);
//Ext.Msg.alert(‘提示‘, ‘载入成功‘);
}
,
failure: function (form, action) {//加载失败的处理函数
Ext.Msg.alert(‘提示‘, ‘载入失败‘);
}
});
}
}
修改后台
string data = http://www.mamicode.com/JsonHelper.GetJsonString(S_VOYAGE_PORT.Find(ID));
string sa = "{success: true ,data:" + data + "}";
data 格式 {id:‘‘,name:‘‘,age:‘‘}
Ext js form表单的提交