zoukankan      html  css  js  c++  java
  • thymeleaf 使用javascript定义数组报错

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

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

    org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "
                    {checkbox: true, fixed: true}
                    , {field: 'originalFileName', title: '文件名',  400, sort: true}
                    , {field: 'fileType', title: '文件类型',  100}
                    , {field: 'fileSize', title: '文件大小',  110, sort: true}
                    , {field: 'createTime', title: '上传时间',  170, sort: true}
                    , {field: 'dpStatus', title: '数据处理状态',  122, templet: '#statusTpl', sort: true}
                    , {field: 'updateTime', title: '数据处理完成时间',  170, templet: '#updateTimeTpl', sort: true}
                    , {fixed: 'right', title: '操作', align: 'center',  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',  80, sort: true, fixed: 'left'}
                    , {field: 'xxx', title: '记录日期',  80}
                    , {field: 'xxx', title: '操作人ID',  80, sort: true}
                    , {field: 'xxx', title: '',  80}
                    , {field: 'xxx', title: '签名',  177}
                    , {field: 'xxx', title: '积分',  80, sort: true}
                    , {field: 'xxx', title: '评分',  80, sort: true}
                    , {field: 'xxx', title: '职业',  80}
                    , {field: 'xxx', title: '财富',  135, sort: true}
                ]
            ]

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

    <script th:inline="none">
    </script>
  • 相关阅读:
    解决Error: Cannot find module 'node-sass'问题
    SourceTree免登录使用
    git commit之后,想撤销commit
    vue生命周期
    Azure DevOps Azure Repos Git How-to Guides Use SSH key authentication
    FlagsAttribute Class
    serilog Debugging and Diagnostics
    Configuration error of serilog
    Serilog settings appsetting 配置的加载
    Kibana Query Language
  • 原文地址:https://www.cnblogs.com/schoolbag/p/9679014.html
Copyright © 2011-2022 走看看