引入js、css:
<link href="${ctx}/static/comp/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="${ctx}/static/comp/ligerUI/js/core/base.js" type="text/javascript"></script>
<script src="${ctx}/static/comp/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
<script src="${ctx}/static/comp/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>
html:
<input type="text" class="txt1" id="sexId" />
js:
$("#sexId").ligerComboBox({
data: [{ id: 1, name: '男' },{ id: 2, name: '女' }],
textField: 'name',
valueField :'id',
valueFieldID:'sex',
value:1
});
说明:
data:json数据
textField:要显示的字段 key
valueField :要提交的值的 key
valueFieldID:要提交时的name 对应的名称
value:默认值 与valueField相对应
注意:
html的input标签的id sexId 不能与控件的valueFieldID属性值相同,否则请求400
实例:
$("#PROTOCAL_ID").ligerComboBox({
url:path+'/common/protocolTypeCombobox?isAll=false',
textField: 'name',
valueField: 'code',
valueFieldID: 'protocalId',
value:"${device.protocalId}"
});
清空 input框中的value(sexId为input的ligerComboBox 对象)
sexId.setValue("");
异步树加载数据的时候 ,有时默认input会出现 null文本:
解决:源码ligerComboBox.js
//设置值到 文本框和隐藏域
_changeValue: function (newValue, newText)
{
var g = this, p = this.options;
g.valueField.val(newValue);
if (p && p.render)
{
g.inputText.val(p.render(newValue, newText));
}
else
{ //添加
if(newText == null || newText == "null"){
newText="";
}
g.inputText.val(newText);
}