layui中表格渲染报错, 与Thymeleaf语法冲突
table.render({
elem: '#fileList'
,url: 'testTable.json'
,page: true
,id: 'testReload'
,toolbar: '#toolbarDemo'
,cols: [[
{type:'checkbox', fixed: 'left'}
,{field: 'id', title: 'ID', sort: true,width:80}
,{field: 'userId', title: '所属人',width:80, sort: true}
,{field: 'name', title: '文件名',edit: 'text',width:160 }
,{field: 'type', title: '类型',edit: 'text',width:80, sort: true}
,{field: 'size', title: '大小(KB)',width:100, sort: true}
,{field: 'gmtCreate', title: '上传时间',width:200, sort: true}
,{fixed: 'right', title:'操作', toolbar: '#fun', width:160}
]]
});
注意 [[ ]]
在Thymeleaf中是一种语法
如果想在js中用到 [[ ]]
官方文档中说明需要在引用js的标签中加入th:inline=“none”
<script type="text/javascript" th:inline="none">
</script>
补充另外一种更好的方法, 不会语法冲突
<script type="text/javascript">
[[]]
变为
[
[
]
]
</script>