SoFunction
Updated on 2025-04-12

Layui An instance of escaped data in table

Method 1Iterate through done callback:

//Method-level rendering    ({
      id: 'demoList',
      elem: '#demoList'
      , url: 'showDemoList'
      , cols: [[
        {checkbox: true, fixed: true, width: '10%'}
        , {field: 'id', title: 'serial number', width: '15%', sort: true}
        , {field: 'pipe_id', title: 'Institution ID', width: '15%'}
        , {field: 'bank_id', title: 'Bank ID', width: '10%'}
        , {field: 'pipe_cost', title: 'cost', width: '10%'}
        , {field: 'status', title: 'state', width: '20%'}
        , {field: 'remark', title: 'operate', width: '20%', toolbar: '#toolBar'}
      ]],
      done: function (res, curr, count) {
        //If it is an asynchronous request for data, res is the information returned by your interface.        //If it is a direct assignment method, res is: {data: [], count: 99} data is the current page data, and count is the total data length        $("[data-field='status']").children().each(function () {
          if ($(this).text() == '0') {
            $(this).text('efficient');
          } else if ($(this).text() == '1') {
            $(this).text('invalid');
          }
        });
      }
      , page: true
      , height: 'full-83'
    });

Method 2Implemented through Layui's templet template:

 , {field: 'status', title: 'state', width: '20%',templet:'#status'}
 
<script type="text/html" >
  {{# if(=='0'){ }}
  efficient
  {{# }else{ }}
    invalid
  {{# } }}
</script>

The above example of the escaping data in table is all the content I share with you. I hope you can give you a reference and I hope you support me more.