Layui table表格中select批量数据回显

视图层:

<!-- 设计类型 -->
<script type="text/html" id="quote_sjlx">
    <div class="layui-form" >
    <select class="layui-form quote_sjlx" lay-filter="quoteSelectTb" name="quote_sjlx" data-dataindex="{{d.LAY_TABLE_INDEX}}" value="{{d.quote_sjlx}}">
        <option value=""> </option>
    </select>
    </div>     
</script>
<!-- 低密度项目-户型类型 -->
<script type="text/html" id="quote_dmd_hxlx">
    <div class="layui-form" >
    <select class="layui-form quote_dmd_hxlx" lay-filter="quoteSelectTb" name="quote_dmd_hxlx" data-dataindex="{{d.LAY_TABLE_INDEX}}" value="{{d.quote_dmd_hxlx}}">
        <option value=""> </option>
    </select>
    </div>     
</script>

JS:

function selecetLoadBjxx(){
    var nameArr = ['quote_sjlx','quote_dmd_hxlx'] // 定义批量select回显字段
    for(var i in nameArr){
        $("." + nameArr[i]).each(function() {
            var that = $(this);
            var name = that[0].name;
            var dataIndex = that[0].dataset.dataindex; //当前行select下标
            var val = viewObj.tbBaojia[dataIndex][name]; //当前select的值
            // that.val(val) 
            that.children("option").each(function() {  //遍历添加selected属性
                // 判断需要对那个选项进行回显
                if (this.value == val) {
                    // 进行回显
                    $(this).attr("selected","selected");
                }
            });
        })
    } 
    form.render('select');  //数据处理完,重新渲染表单
}
发布了27 篇原创文章 · 获赞 7 · 访问量 3531

猜你喜欢

转载自blog.csdn.net/qq_33966519/article/details/103618377