创建容器
xm-select-demo,选择容器隐藏赋值取值表单;
<div id="selected_box" class="layui-input-inline xm-select-demo" style="width:150px;">
<input type="hidden" id="poi_category_id"></div>
异步获取代码
//获取分类;
$.ajax({
type: 'get',
url: "./api/api.php?act=getCategory&token=3cab7ce4142608c0f40c785b5ab5ca24",
data: {},
dataType: "json",
success: function (res) {
var data = [];
for (var i = 0; i < res.data.length; i++) {
data.push({name: res.data[i].category_name, value: res.data[i].category_id});
}
xmSelect.render({
el: '#selected_box',
theme: {
color: 'rgba(255, 87, 34,0.8)',
},
language: 'zn',
filterable:true,
data: data,
on: function(data){
var selectArr = data.arr;
var seachArr = [];
for (var j = 0; j < selectArr.length; j++) {
seachArr.push(selectArr[j].value)
}
$("#poi_category_id").val(seachArr.toString());
}
})
},
error: function (err) {
console.log(err)
}
});
赋值表单
$("#poi_category_id").val(seachArr.toString());
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!