jquery combox与combobox使用

来源:互联网 发布:气体栓塞 知乎 编辑:程序博客网 时间:2024/06/04 23:23
今天使用combobox 把我惹毛了。遇到情况有:

struts2 配置问题;

后台java代码微笑 * Function  : 加载Combobox数据给前台
     * @author   : tim
     * @return
     */
    public void goComboboxMain(){
        /**
        JSONObject datas = loginInfoService.findLoginInfo(request);
        response.setCharacterEncoding(Constants.ENCODING_UTF8);
        response.getWriter().print(datas.toString());
         * */
        List<TestJqueryEasyuiCombobox> list = new ArrayList<TestJqueryEasyuiCombobox>();
        JSONObject datas = new JSONObject();
        for (int i = 0; i < 5; i++) {
            TestJqueryEasyuiCombobox s = new TestJqueryEasyuiCombobox(i+"","text"+i);
            list.add(s);
        }
        jsonArray = net.sf.json.JSONArray.fromObject(list);
        System.out.println("goCombobox == "+jsonArray.toString());
        response.setCharacterEncoding(Constants.ENCODING_UTF8);
        try {
            response.getWriter().print(jsonArray.toString());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
使用stream 输出到前台。这样的输出要控制字符串。

前台使用了:


 <input class="easyui-combobox"  
   id="cc" 
   name="test" 
   multiple="false"   
   url="<%=root%>/ospm/jqueryEasyui/goComboboxMain.action" 
   valueField="id"  
   textField="text"  
   panelHeight="auto" 
   />

这样才没有出错。这里是multiple 属性不管你配置true还是false都会有多选。这里我采用的是去掉这个属性,就成了单选。


如果combobox采用这样的形式:

 <input class="easyui-combobox"  
   id="cc" 
   name="test" 
   />

js中使用

    $('#cc').combobox( {
            width:150,
            listWidth:150,
            listHeight:100,
            url:'<%=root%>/ospm/jqueryEasyui/goComboboxMain.action',
            valuefield:'id',
            textField:'text',
            multiple:true,//为true时支持多选
            editable:false,
            formatter: function(row){
                    alert("id == "+row.id+" values == "+row.text);
                    var opts = $(this).combobox('options');
                    return row[opts.textField];
                }
           
            });
        }

这样的话,使用getValue方法是获取不到值,对于这里我也感到郁闷。及时获取到,也是空的值。

但是使用getText能获得Value。


0 0