方法一 通過done回調進行遍歷:
//方法級渲染 table.render({ id: 'demoList', elem: '#demoList' , url: 'showDemoList' , cols: [[ {checkbox: true, fixed: true, width: '10%'} , {field: 'id', title: '編號', width: '15%', sort: true} , {field: 'pipe_id', title: '機構ID', width: '15%'} , {field: 'bank_id', title: '銀行ID', width: '10%'} , {field: 'pipe_cost', title: '成本', width: '10%'} , {field: 'status', title: '狀態', width: '20%'} , {field: 'remark', title: '操作', width: '20%', toolbar: '#toolBar'} ]], done: function (res, curr, count) { //如果是異步請求數據方式,res即為你接口返回的信息。 //如果是直接賦值的方式,res即為:{data: [], count: 99} data為當前頁數據、count為數據總長度 $("[data-field='status']").children().each(function () { if ($(this).text() == '0') { $(this).text('有效'); } else if ($(this).text() == '1') { $(this).text('無效'); } }); } , page: true , height: 'full-83' });
方法二 通過layui的templet模板實現:
, {field: 'status', title: '狀態', width: '20%',templet:'#status'} <script type="text/html" id="status"> {{# if(d.status=='0'){ }} 有效 {{# }else{ }} 無效 {{# } }}</script>
以上這篇layui 對table中的數據進行轉義的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。
新聞熱點
疑難解答