Extjs4 多选combo

 ssh项目中需要用到多选combo,Extjs4提供了multiSelect配置项:

  
  
  
  
  1. multiSelect : Boolean 
  2. If set to true, allows the combo field to hold more than one value at a timeand allows selecting multiple items from the dropdown list. The combo's text field will show all selected values separated by the delimiter. 
  3.  
  4. Defaults tofalse 

于是配置combo:

  
  
  
  
  1.     xtype:'LifechannelCombo'
  2.     id:'channelid'
  3.     name:'channelname'
  4.     fieldLabel:'推送渠道'
  5.     multiSelect:true
  6.     labelAlign: 'right'
  7.     labelWidth: 80, 
  8.     width:260, 
  9.     selectOnFocus: true 
  10. }, 

然后form提交,在action中

  
  
  
  
  1. HttpServletRequest request = ServletActionContext.getRequest(); 
  2. String channelid = request.getParameter("channelname"); 

获取,结果发现channelid只是选中的第一个值。

然后进行调试找问题,首先获取此下拉框组件的value:

  
  
  
  
  1. var channel = Ext.getCmp('channelid').getValue(); 
  2. alert(channel); 

发现是正常的,会将多选的值按照逗号分割拼成字符串。

又以为form提交方式问题,又获取form的values:

  
  
  
  
  1. var formvalue = form.getValues(); 

通过设断点发现formvalue中的值也是正确的按照逗号分割的结果字符串。

然后就怀疑是传值过程中出现了问题,设断点查看request,

发现是这样的String数组,request.getParameter()只能得到第一个String,又查到另有一个方法getParameterValues(),返回的是String[],于是后台获取方式改为:

  
  
  
  
  1. HttpServletRequest request = ServletActionContext.getRequest(); 
  2. String[] channelid = request.getParameterValues("channelname"); 

然后将channelid从数组中取出来进行处理存入数据库即可。

 

你可能感兴趣的:(职场,extjs4,取值,休闲,多选combo)