Easyui combobox设置值和文本的几种方式和问题

来源:互联网 发布:php的框架有哪些 编辑:程序博客网 时间:2024/06/06 05:36

Easyui combobox设置值和文本的几种方式和问题
1、在Easyui 帮助文档中,我们可以看到combobox是继承自combo,combo中有两上方法:setText、setValue。

这里写图片描述

这里写图片描述

2、combobox设置值的方式一:

//获取从后台传过来的客户idvar 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事件

这里写图片描述

原创粉丝点击