环境: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');*/