layui是大家比较喜欢的后台搭建框架,但它在给大家带来便利的同时,有会出现一些问题,比如select绑定动态数据不显示。
我在项目中就遇到了这个问题,解决方法如下
layui.use(['form' ], () => {
let _this = this //绑定this
let form = layui.form
let selectEl = $("#categoryId"); //绑定需要重新渲染的select
selectEl.empty();
selectEl.append();
$.each(_this.zhiXuSelet, function (index, item) {//遍历数组
selectEl.append(new Option(item.title, item.identifier));//添加
});
form.render('select');
})