问题描述
Ext的combox设置成只读的,让别人不能下拉?但是要显示,如果加上disable:true的话,又无法把值传到后台?本人用的Ext版本是3.0的,下面是代码 var form1_id = new Ext.form.ComboBox({ id: 'form1_id', name: 'id', hiddenName: 'id', fieldLabel: '*所属区域', editable : false, typeAhead: true, lazyRender: true, readOnly:true, mode: 'remote', store: new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '<c:url value="。。。。.do" />?action=id_load' }), reader: new Ext.data.JsonReader({ root: 'data', id: 'id' }, ['id', 'Name'] ) }), valueField: 'id', displayField: 'Name' });怎么设置让显示出来后别人只能看,而无法操作,同时值要传到后台?这里设置的 readOnly:true没用 问题补充:jkam 写道
解决方案
<script type="text/javascript">Ext.onReady(function(){ var data = {"items":[{"name":"yyf123","password":"123","userId":1},{"name":"yyf345","password":"456","userId":2}],"result":2} ; var store = new Ext.data.JsonStore({autoLoad:true, fields:[{name:'name',type:'String'}, {name:'password',type:'String'}, {name:'userId',type:'int'} ], root:'items', data: data });myComboBox = Ext.extend(Ext.form.ComboBox, { store: store, emptyText: '请选择', mode: 'local', triggerAction: 'all',maxHeight:80, valueField: 'userId', displayField: 'name', lastQuery:"",notShow:false, //加一个属性 默认为FALSErenderTo: 'combo', initComponent : function(config){Ext.apply(this,config) Ext.form.ComboBox.superclass.initComponent.call(this); },onTriggerClick : function(){//如果if为真 则直接return 下拉不出来 if( this.readOnly || this.disabled || this.notShow){return;}if(this.isExpanded()){this.collapse();this.el.focus();}else {this.onFocus({});if(this.triggerAction == 'all') {this.doQuery(this.allQuery, true);} else {this.doQuery(this.getRawValue());}this.el.focus();} },HideCombo:function(b){ //加一个函数 this.notShow = b;}}) var combo = new myComboBox();Ext.get("show").on("click",function(){combo.HideCombo(false)})Ext.get("readOnly").on("click",function(){combo.HideCombo(true)combo.setEditable(false)})}); </script> </head> <body> <div id="combo"><div><input type="button" id="show" value="能下拉"><input type="button" id="readOnly" value="不能下拉"> </body></html>不知道这样 你满不满意
解决方案二:
就是再写一个用于传值的隐藏域
解决方案三:
设置一个hiddenField
解决方案四:
...readOnly : true,hideTrigger : true,...
解决方案五:
var store = new Ext.data.SimpleStore({ fields: ['abbr', 'state'], data : Ext.exampledata.res_type // from states.js//获得数据 }); var combo = new Ext.form.ComboBox({ store: store, displayField:'state', typeAhead: true, mode: 'local', triggerAction: 'all', emptyText:'选择物品类型', //selectOnFocus:true, //forceSelection:true, disable:true //resizable:true }); combo.applyTo('resType');