thymeleaf中使用layui 的自動化表格顯示物件的某一屬性值(格式化輸出)
阿新 • • 發佈:2019-01-23
類似easyui 的formatter
網上沒找到方法,最後看的官方文件自己試著可以用了,時間 超連結 同理
分頁返回blog list blogType物件無法直接在表格中顯示 需要使用 ,templet:
js
<script th:inline="javascript" type="text/javascript" id="blogType">
{{# if( d.blogType != null){ }}
{{ d.blogType.typeName }}
{{# } }}
</script>
表格<thead> <tr> <th lay-data="{checkbox:true, fixed: true}"></th> <th lay-data="{field:'id', width:'50', sort: true, fixed: true}">編號</th> <th lay-data="{field:'title', width:'250'}">標題</th> <th lay-data="{field:'releaseDate', width:'200', sort: true}">釋出日期</th>型別 <th id="blogType" lay-data="{field:'blogType', width:'200',templet: '#blogType'}">部落格型別</th> <th lay-data="{fixed: 'right', width:'250', align:'center', toolbar: '#barDemo'}"></th> </tr> </thead>
這樣就可以顯示了
補:如果顯示正常但是瀏覽器報錯在{ {}} 可以選擇修改layui的預設模板標籤({{ }}) 可能是和thymeleaf衝突,而且不同瀏覽器對這個處理不同。
templet屬性值 是id,該id也是js程式碼塊的id,通過使用d.var引用該表格中的欄位即可,{{# 這裡是寫js程式碼}} {{這裡填變數,直接輸出}} 如果是html就不需任何標籤了。
注意html不能在{{# }} {{}}中更加具體看API 。