After refreshing the 00012-layui table, the buttons on the toolbar are invalid

Posted May 26, 20201 min read

Toolbar buttons:

<script type = "text/html" id = "taskListTable-toolbar">
   <div class = "layui-btn-container">
      <button class = "layui-btn layui-btn-sm" data-type = "cancelTask"> The task is invalid </button>
   </div>
</script>

Monitor event of toolbar button in sample code:

table.on('toolbar(taskListTable)', function(obj) {
          switch(obj.event) {
              case 'cancelTask':
                  active.cancelTask  ()
                  break;
          };
});

This code, after tableIns.reload() ;, the event is invalid.

Solution:

$("body"). on('click', '. layui-btn-container .layui-btn', function() {
    var type = $(this) .data('type');
    active [type]? active [type].call(this):'';
});

The corresponding method of data-type = "cancelTask":

var active = {
    cancelTask:function() {
        ////...
    }
}