html
<select name="channelType" id="channelType" lay-verify="required">
<script id="selectChnTypes" type="text/html">
<option selected="selected" value=''>-----------请选择-----------</option>
<!--layui模板引擎,动态添加后台数据-->
{{# layui.each(d.listChannelType, function(index, item){ }}
<option value='{{ item.CHN_CODE }}'>{{ item.CHN_NAME }}</option>
{{# }); }}
</script>
</select>
js
layui.use('laytpl', function(){
var laytpl = layui.laytpl;
function queryAllBsChannel(){
$.ajax({
url: xxx,
type: "POST",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(xxx),
beforeSend: xxx,
success: function (res) {
var data = res.info;
if (data) {
var list = {
"listChannelType":data
}
var getTpl = $("#selectChnTypes").get(0).innerHTML;
var view = $("#channelType").get(0);
laytpl(getTpl).render(list, function (html) {
view.innerHTML = html;
});
}
form.render('select');
}
});
}
});