37 lines
725 B
Markdown
37 lines
725 B
Markdown
## 远程搜索
|
|
|
|
:::demo
|
|
```html
|
|
<div id="demo1"></div>
|
|
|
|
<script>
|
|
var demo1 = xmSelect.render({
|
|
el: '#demo1',
|
|
autoRow: true,
|
|
toolbar: { show: true },
|
|
filterable: true,
|
|
remoteSearch: true,
|
|
remoteMethod: function(val, cb, show){
|
|
//这里如果val为空, 则不触发搜索
|
|
if(!val){
|
|
return cb([]);
|
|
}
|
|
//这里引入了一个第三方插件axios, 相当于$.ajax
|
|
axios({
|
|
method: 'get',
|
|
url: 'https://www.fastmock.site/mock/98228b1f16b7e5112d6c0c87921eabc1/xmSelect/search',
|
|
params: {
|
|
keyword: val,
|
|
}
|
|
}).then(response => {
|
|
var res = response.data;
|
|
cb(res.data)
|
|
}).catch(err => {
|
|
cb([]);
|
|
});
|
|
},
|
|
})
|
|
</script>
|
|
```
|
|
:::
|