使用layui动态获取table数据,在操作中绑定了工具条,点击工具条里的按钮却无法触发obj.event事件
页面代码
//页面代码
<div class="layui-form-item">
<label class="layui-form-label">单位选择</label>
<div class="layui-input-block">
<button class="layui-btn">新增</button>
</div>
<div class="layui-input-block" style="width: 500px">
<table id="chooseUnit"></table>
</div>
</div>
js代码
//js代码
table.render({
elem : '#chooseUnit'
, url : url
, height :300
, cols :
[
[
{type: 'numbers', title: '序号', align:"center", width: 100}
, {field: 'orgName', title: '单位名称', align:"center"}
, {fixed: 'right', title: '操作', align:"center", templet: '#barDemo'}
]
]
, id : 'chooseUnit'
, page : false
})
table.on('tool(chooseUnit)', function(obj){
if(obj.event === 'pass'){
console.log('click remove')
}
});
绑定的工具条
<script id="barDemo" type="text/html">
<a class="blueText" lay-event="remove">移除</a>
</script>
解决方法
在 <table id="chooseUnit" ></table>里加 lay-filter="chooseUnit" 就可以了