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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM