Layui完美解决 表格+Select 动态渲染问题


好不容易解决了下拉遮挡问题,渲染又出问题了……

百度各种教程,都是需要ajax先获取到option的取值,然后再去刷新…好麻烦,跟我之前的代码不相符,因为我还需要有改变select的绑定事件!!!

现在完美解决了,贴代码!!!(老规矩,为了直观,只贴重点)

<script>
    layui.use(['laydate','form', 'table'], function() {
        
        var tableIn = table.render({
            
            size: 'lg',
            cols: [
                [
                    
                    { field: 'check', width: 120, title: '状态', templet: function (d) {
                            var arrStatus = [['-','未审核'],['Y','通过'],['N','未通过']];
                            var html="<select name='status' lay-filter='check'>";
                            for(var i=0;i<arrStatus.length;i++){
                                var strselected = '';
                                if(arrStatus[i][0] == d.check){strselected = "selected"};
                                html=html+"<option value='"+arrStatus[i][0]+"' "+strselected+">"+arrStatus[i][1]+"</option>";
                            };
                            html = html +"</select>";
                            return html;
                        }},
                    
                ]
            ],
           
           
        });
      
       
        //监听启用停用事件
        form.on('select(check)', function(obj) {
            loading = layer.load(1, { shade: [0.1, '#fff'] });
            var parentTr = obj.othis.parents("tr");
            var id = $(parentTr).find("td:eq(0)").text() 
            var status = obj.value;
            $.post('{:url("commentStatus")}', { 'id': id, 'check': status }, function(res) {
                // console.log(res);
                layer.close(loading);
                var start = typeof res =='string'?JSON.parse(res):res;
                if (start.code == 1) {
                    layer.msg(start.msg, { time: 1000, icon: 1 });
                    form.render();
                } else {
                    layer.msg(start.msg, { time: 1000, icon: 2 });
                    if (obj.elem.checked){
                        obj.elem.checked = false;
                    }else{
                        obj.elem.checked = true;
                    }
                    form.render();
                    return false;
                }
            })
        });
      
    });
</script>



最新回复 (0)
发新帖