layui 表格的下拉选择

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui 模仿下拉框 </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" href="../js/plugins/layui/css/layui.css"/>
    <style>
        body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td {
            margin: 0;
            padding: 0;
            list-style: none;
            border: none;
        }

        html, body {
            position: relative;
            background: #EDF0F5;
            color: #505458;
            font-family: "微软雅黑";
            font-size: 14px;
        }

        .layui-table thead tr {
            background-color: #fff;
        }

        .laytable-cell-1-sel {
            overflow: inherit;
        }

        .layui-table-cell span {
            font-weight: bold;
        }

        .layui-table-body tbody tr {
            height: 50px;
        }

        .selectDemo {
            height: 30px;
            border: 1px solid #e6e6e6;
            border-radius: 4px;
        }

    </style>
</head>
<body>

<table class="layui-hide" id="test"></table>


<script type="text/html" id="select">
    <select lay-filter="selDome" class="selectDemo" data-id="{{d.id}}" lay-ignore onchange="selectDemo(this)">
        {{# layui.each(d.sel, function(index, item){ }}
            <option value="{{item}}">{{item}}</option>
        {{# }); }}
    </select>
</script>
<script src="../assets/scripts/jquery.min.js"></script>
<script src="../js/plugins/layui/layui.all.js" type="text/javascript" charset="utf-8"></script>


<script>


    var table = layui.table
        , form = layui.form;

    table.render({
        elem: '#test'
        , url: 'index.json'
        , sort: false
        , unresize: true
        , skin: 'line'
        , cols: [[
            {type: 'numbers'}
            , {field: 'id', title: 'ID', width: 100}
            , {field: 'username', title: '用户名', templet: '#usernameTpl'}
            , {field: 'city', title: '城市'}
            , {field: 'wealth', title: '财富', minWidth: 120}
            , {field: 'sel', title: '下拉选择', width: 110, templet: '#select'}
        ]]
    });

    function selectDemo(a) {
        console.log($(a).attr('data-id'));
        console.log($(a).val());
    }

</script>

</body>
</html>

lindex.json

{
  "code": 0,
  "count": 1000,
  "data": [
    {
      "city": "城市-0",
      "classify": "作家",
      "experience": 255,
      "id": 10000,
      "logins": 24,
      "score": 57,
      "sex": "女",
      "sign": "签名-0",
      "username": "user-0",
      "wealth": 82830700,
      "sel":["测试1","测试2","测试3","测试4"]
    },
    {
      "city": "城市-1",
      "classify": "词人",
      "experience": 884,
      "id": 10001,
      "logins": 58,
      "score": 27,
      "sex": "男",
      "sign": "签名-1",
      "username": "user-1",
      "wealth": 64928690,
      "sel":["测试1","测试2","测试3"]
    },
    {
      "city": "城市-2",
      "classify": "码农",
      "experience": 884,
      "id": 10003,
      "logins": 58,
      "score": 27,
      "sex": "女",
      "sign": "签名-1",
      "username": "user-1",
      "wealth": 64928690,
      "sel":["测试1","测试2","测试3"]
    },
    {
      "city": "城市-3",
      "classify": "码农",
      "experience": 884,
      "id": 10004,
      "logins": 58,
      "score": 27,
      "sex": "女",
      "sign": "签名-1",
      "username": "user-1",
      "wealth": 64928690,
      "sel":["测试1","测试2","测试3"]
    }
  ],
  "msg": ""
}

页面显示

这里写图片描述