xm-select/docs/mds/ZM04.md
2019-10-17 21:21:39 +08:00

920 B

远程搜索

:::demo

<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>

:::