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();
}
}
前台使用了:
<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。