layui-xm-select插件的应用

环境:layui 2.9.16, xm-select 1.2.4

xm-select官方文档:

https://cdn.faysunshine.com/file/xm-select/v1.2.4/index.html#/component/install
const communityId = xmSelect.render({
            el: '#community_id',
            prop: {name: 'community_name',value: 'id'}, // 自定义属性, 很关键!!!
            radio: true,
            data: [],
            clickClose: true,
            filterable: true,
            remoteSearch: true,
            remoteMethod: function(val, cb, show){
                //这里如果val为空, 则不触发搜索
                if(!val){return cb([]);}
                
                $.ajax({
                    url: '/admin/resale/getCommunity/',
                    type: 'GET',
                    data: {"communityName": val},
                    dataType: 'json',
                    success: function(res) {
                        cb(res.data);
                    },
                    error: function(xhr, status, error) {
                        cb([]);
                    }
                });
            }
        });
        // communityId.setValue([{community_name:'test',id:7}]); // 赋值
        communityId.update({data:[{community_name: 'test',id: 7, selected: true}]}); // 远程数据动态赋值
        /*$.get('/admin/resale/getCommunityName/',{"communityId":{$data.community_id}},function(res){
            communityId.update({data: [{community_name:"测试",id:7, selected:true}],autoRow: true,});
        },'json');*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值