Easyui combobox设置值和文本的几种方式和问题
1、在Easyui 帮助文档中,我们可以看到combobox是继承自combo,combo中有两上方法:setText、setValue。
2、combobox设置值的方式一:
//获取从后台传过来的客户id
var customerId = '${customer.id}';
//初始化顾客下拉列表
$("#customerCombobox").combobox({
url : "${basePath}/customer/queryCustomers.do?",
valueField:'id',
textField:'name',
width:150,
dataPlain : true,
//设置默认值
value : customerId
});
此种方式可以正常设置,运行如下图:
3、combobox设置值的方式二:
//初始化顾客下拉列表
$("#customerCombobox").combobox({
url : "${basePath}/customer/queryCustomers.do?",
valueField:'id',
textField:'name',
width:150,
dataPlain : true
});
//设置值
$("#customerCombobox").combobox('setValue','${customer.id}');
//设置显示文本
$("#customerCombobox").combobox('setText','${customer.name}');
此种方式,没有设置成功,运行如图:
4、combobox设置值的方式三:
//初始化顾客下拉列表
$("#customerCombobox").combobox({
url : "${basePath}/customer/queryCustomers.do?",
valueField:'id',
textField:'name',
width:150,
dataPlain : true,
onLoadSuccess: function(){
//设置默认值
$(this).combobox('setValue','${customer.id}');
}
});
此种方式设置成功,运行结果如图:
5、小结 :
Easyui 中的onLoadSuccess说明:
tree和combotree:当数据加载完成之后触发onLoadSuccess事件。
form:当数据开始加载的时候触发onLoadSuccess事件