console
layui.use(() => {
const matches= 'sdfdsfsdf'.matchAll(new RegExp('sd','gi'))
for (const match of matches) {
console.log(match);
}
const { table, $ } = layui
const dataSource = [{ username: '1', sex: 'nan', edit: false }]
const tableInstance = table.render(getTableOption(dataSource));
function getTableOption(data) {
return {
elem: '#demo',
height: 420,
data: data,
title: '用户表',
cols: [[
{
field: 'username', title: '用户名', width: 80, templet: function (d) {
return d.edit ? `<select lay-ignore class='a-input' data-index=${d.LAY_INDEX} value=${d.username}>
<option value='2'> 1</option>
<option value='3'> 2</option>
</select>` : d.username
}
},
{ field: 'sex', title: '性别', width: 80, sort: true },
{ width: 150, align: 'center', toolbar: '#barDemo' }
]]
}
}
$('.table-add-btn').on('click', function () {
dataSource.push({
username: '2',
sex: 'nv',
edit: true
})
tableInstance.reload(getTableOption(dataSource))
})
$('.table').on('change', '.a-input', function () {
console.log($(this).val())
console.log($(this).data('index'))
const index = $(this).data('index')
const cahe = dataSource[index - 1]
dataSource[index - 1].sex = 1111
dataSource[index - 1].username = $(this).val()
tableInstance.reload(getTableOption(dataSource))
})
})
<div class='table'>
<table class="layui-hide" id="demo" lay-filter="test"></table>
<script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
</script>
<button class="table-add-btn">添加</button>
</div>