thymeleaf 使用javascript定义数组报错

js中免不了的要用的数组,一维的二维的三维的

但是当用到thymeleaf作为模版时候会有一些坑,导致数组不能用

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "
                {checkbox: true, fixed: true}
                , {field: 'originalFileName', title: '文件名', width: 400, sort: true}
                , {field: 'fileType', title: '文件类型', width: 100}
                , {field: 'fileSize', title: '文件大小', width: 110, sort: true}
                , {field: 'createTime', title: '上传时间', width: 170, sort: true}
                , {field: 'dpStatus', title: '数据处理状态', width: 122, templet: '#statusTpl', sort: true}
                , {field: 'updateTime', title: '数据处理完成时间', width: 170, templet: '#updateTimeTpl', sort: true}
                , {fixed: 'right', title: '操作', align: 'center', width: 300, toolbar: '#operating'}
            " (template: "textManagement" - line 125, col 22)
    at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:131)
    at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:62)
    at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:44)
    at org.thymeleaf.engine.EngineEventUtils.parseAttributeExpression(EngineEventUtils.java:220)

这里只接触最外层异常,而出现异常的位置

<script>
    var cols=[[
        {field:'checkBox',checkbox: true, fixed: true}
        ,{field:'username', title: '用户名'} //width 支持:数字、百分比和不填写。你还可以通过 minWidth 参数局部定义当前单元格的最小宽度,layui 2.2.1 新增
        ,{field:'mobile', title: '手机号', sort: true}
        ,{field:'nickname', title: '昵称'}
        ,{field:'lastLoginTime', title: '最后登录时间'}
        ,{field:'ip', title: '最后登录ip', align: 'center'} //单元格内容水平居中
        ,{field:'op',title: '操作', align:'center', toolbar: '#toolBars'} //这里的toolbar值是模板元素的选择器
    ]];
</script>

thymeleaf会把[[]]中的内容作为内联取值块解析,而不是数组。可以在cols的后面换行

解决办法:

方法一:回车换行如下:

, cols: [
            [ //表头
                {field: 'xxx', title: 'ID', width: 80, sort: true, fixed: 'left'}
                , {field: 'xxx', title: '记录日期', width: 80}
                , {field: 'xxx', title: '操作人ID', width: 80, sort: true}
                , {field: 'xxx', title: '', width: 80}
                , {field: 'xxx', title: '签名', width: 177}
                , {field: 'xxx', title: '积分', width: 80, sort: true}
                , {field: 'xxx', title: '评分', width: 80, sort: true}
                , {field: 'xxx', title: '职业', width: 80}
                , {field: 'xxx', title: '财富', width: 135, sort: true}
            ]
        ]

方法二:或者在script标签里 th:inline="none" 就可以了,默认是th:inline="text"

<script th:inline="none">
</script>