layui table 添加radio框 并且数据初始化显示
1、html内容
<table class="layui-hide" id="table-info" lay-filter="table-info"></table>
<script type="text/html" id="barOpt">
{literal}
<input type="radio" name="is_promote_{{ d.id }}" data-id="{{ d.id }}" value="1" title="是" lay-filter="promote_event">
<input type="radio" name="is_promote_{{ d.id }}" data-id="{{ d.id }}" value="2" title="否" lay-filter="promote_event">
{/literal}
</script>
2、radio表单事件
form.on('radio(promote_event)', function (data) {
var vals=data.value;
});
3、table初始化回显
var objs = {
elem: 'table-info',
method: 'post',
isPage: true,
limits: 10,
toolbar: '#test-table-toolbar',
cols: [
[
{ type: 'checkbox' },
],
],
dones: function (res, curr, count){ //主要这里
var dataArr = res.data;
for (var i = 0; i < dataArr.length; i++) {
$('tbody').find('tr[data-index="' + i + '"]').find('input[type="radio"]').eq(0).prop('checked',true)
form.render('radio');
};
},
url: '',