Layui select 动态绑定数据多个数据 (通过form.on获取)
html 代码<form><select name="select1" id="select1" lay-verify="required" lay-search="" lay-filter ="select1"><option value="">直接选择或搜索选择</option></select></form>js代码&l
·
html 代码
<form>
<select name="select1" id="select1" lay-verify="required" lay-search="" lay-filter ="select1">
<option value="">直接选择或搜索选择</option>
</select>
</form>
js代码
<script type="text/javascript">
layui.use('laydate', function () {
let form = layui.form;
let data = {
"current": 1,
"size": 500
};
$.ajax({
url: '/kar/xxx/list',
dataType: 'json',
type: 'get',
data: data,
success: function (data) {
if (data) {
let rows = data.rows;
if (rows) {
let content = '';
$.each(rows, function (index, item) {
content += '<option value="'+item.code+'" data-name="'+item.depar+'">'+item.name+':'+ item.code+'</option>'
});
$('#select1').append(content);
//重新渲染 固定写法
layui.form.render("select");
}
}
}
});
form.on('select(select1)', function (r) {
//业务部门
let countryEn = $(r.elem).find("option:selected").attr("data-name");
$("#name").val(countryEn);
});
form.render();
});
</script>
仅供参考
更多推荐
已为社区贡献3条内容
所有评论(0)