Extjs 常见问题:如何提交combobox的值
2012-05-09 17:11 java线程例子 阅读(190) 评论(0) 编辑 收藏 举报转至:http://apps.hi.baidu.com/share/detail/5452956
//提交出去的是显示域,而不是值域 //解决很简单,使用hiddenName即可。 examples/my/test_combobox.html <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>my test</title> <link rel="stylesheet" type="text/css" href="../../../resources/css/ext-all.css" /> <script type="text/javascript" src="../../adapter/ext/ext-base.js"> </script> <script type="text/javascript" src="../../ext-all-debug.js"> </script> <script type="text/javascript"> Ext.onReady(function(){ Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; var sl = [[1,'10'],[2,'100'],[3,'500'],[4,'1000'],[5,'5000']]; var store3 = new Ext.data.SimpleStore({ fields:["code3",'name3'], data:sl }); var simples = new Ext.FormPanel({ baseCls:'x-plain', iconCls : 'icon-info', bodyStyle:'padding:10px', items: [{ xtype:'fieldset', title: '必填项', bodyStyle:'padding:5px', autoHeight:true, labelWidth:60, defaults: {readOnly:true,typeAhead:true,allowBlank:false,anchor:'95%',mode:'local',selectOnFocus:true,triggerAction:'all'}, defaultType: 'combo', items:[ { fieldLabel:"数 量", name:"number", displayField:"name3", valueField:"code3", hiddenName:'number', store:store3, mode:'local', blankText:'数量不能为空' }] }] }); var win = new Ext.Window({ id:'win', layout:'fit', iconCls : 'icon-info', width: 470, height: 280, plain: true, bodyStyle:'padding:5px;', closable:true, collapsible:true, items:simples, buttons: [{ text: '生 成', type: 'submit', handler:function(){ if(simples.form.isValid()){ Ext.MessageBox.show({ title: '请稍等', msg: '正在加载...', progressText: '', width:400, progress:true, closable:false, animEl: 'loding' }); simples.form.doAction('submit',{ url:'post.php',//文件路径 method:'post', params:'', success:function(form,action){ if (action.result.msg=='ok') { Ext.Msg.alert('提交成功',action.result.msg); win.close(); } else { Ext.Msg.alert('提交失败',action.result.msg); } }, failure:function(form,action){ Ext.Msg.alert('错误','服务器出现错误请稍后再试!'); } }); } } },{text: '重 置',handler:function(){simples.form.reset();}} ] }); win.show(); }) </script> </head> <body> </body> </html>补充:
在你的Combobox有id的时候千万不要和hiddenName一样,否则数据不能显示,而数据可以正确返回.这个时候错误很难找.