原来使用的是combobox,可多选。现在需要加入可全选功能,所以使用了combotree,但使用combotree时前台会多出“全选“字段,后台会存入“all”。
解决办法:前台做判断去掉“全选”,后台过滤","。
前台代码:
function formatComboTreeValue(obj) {
var id=$('#'+obj).combotree('getValues');
if(id.indexOf("all") >= 0) {
$.each(id,function(index,item){
if(item=="all"){
id.splice(index,1);
}
});
$('#'+obj).combotree('setValues', id);
var text = $('#'+obj).combotree('getText');
if(text.indexOf('全选') >= 0) {
var texts = text.split(',');
$.each(texts,function(index,ele){
if(ele=='全选'){
texts.splice(index,1);
return false;
}
});
$('#'+obj).combotree('setText',texts.toString());
}
}
后台代码:
String test = ud.getTest();
String sequence = (String) test.subSequence(0, 1);
if (sequence.equals(",")) {
String testString = test.substring(1);
u.setTest(testString );
} else {
u.setTest(testString );
}