最近项目中用到easyUI的searchbox组件,输入查询的值后弹出窗口按照输入的值查询数据,代码如下:
$('#Supplier').searchbox({
searcher: function(value, name) {
alert(value);//获取输入的值
$('#request-supplier-window').window({
href: '/Supplier/SelectSupplier?supplier=' + value + '&r=' + Math.random()
});
$('#request-supplier-window').window('open');
}
});
searchbox的searcher函数中的function(value,name)参数分别是:
- value:searchbox中输入的值,注意是输入的值,在form加载后对searchbox赋值的不是输入的值,这时候searcher函数是获得不到value的
- name:searchbox组件的名字
上面已经说到value值是输入的值,当form加载后赋值给searchbox中的不是输入的值,是以灰色显示的,需要在form的onLoadSuccess事件中赋值给searchbox,这样searcher才能获取到value的值,代码如下:
$('#request-editForm').form({
onLoadSuccess: function(data) {
$('#Supplier').searchbox('setValue',data.Supplier);
}
});
Mikel