layuiデータテーブルtable.renderエラー処理

layui:スプレッドシートtable.renderを使用してエラー処理

まず、エラーメッセージ

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Jan 23 15:20:18 CST 2019
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/Page/test/test.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/Page/test/test.html]")
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.attoparser.ParseException: Could not parse as expression: "
                    {field: 'code', width: 80, title: 'ID', sort: true},
                    {field: 'name', width: 100, title: '用户名'},
                    {field: 'age', width: 80, title: '年龄'},
                    {field: 'gender', width: 80, title: '性别'},
                    {field: 'create_time', width: 80, title: '创建时间'},
                    {field: 'update_time', width: 80, title: '修改时间'},

                " (template: "Page/test/test" - line 57, col 25)
	at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
	at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
	... 64 more
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "
                    {field: 'code', width: 80, title: 'ID', sort: true},
                    {field: 'name', width: 100, title: '用户名'},
                    {field: 'age', width: 80, title: '年龄'},
                    {field: 'gender', width: 80, title: '性别'},
                    {field: 'create_time', width: 80, title: '创建时间'},
                    {field: 'update_time', width: 80, title: '修改时间'},

                " (template: "Page/test/test" - line 57, col 25)
	at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:131)

第二に、問題の処理

公式サイトで与えられたコードによると、私たちはCOLSを見つける:属性パラメータの後に「[[]]」、前と後の2つのブラケットがリンクされています。彼らはそれ以外の場合はエラーになり、分離されなければならない使用する場合は、最良のオプションは、このような、たとえば、ラップすることです
ここに画像を挿入説明

<script>
layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#test'
            , url: '/demo/table/user/'
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增
            , cols:
                [
                    [
                        {field: 'id', width: 80, title: 'ID', sort: true}
                        , {field: 'username', width: 80, title: '用户名'}
                        , {field: 'sex', width: 80, title: '性别', sort: true}
                        , {field: 'city', width: 80, title: '城市'}
                        , {field: 'sign', title: '签名', width: '30%', minWidth: 100} //minWidth:局部定义当前单元格的最小宽度,layui 2.2.1 新增
                        , {field: 'experience', title: '积分', sort: true}
                        , {field: 'score', title: '评分', sort: true}
                        , {field: 'classify', title: '职业'}
                        , {field: 'wealth', width: 137, title: '财富', sort: true}
                    ]
                ]
        });
    });
</script>

ページには、この時点では与えられませんが、何のデータされていない場合。データ形式が誤っている、データ形式が公式解析パッケージに応じて、厳密である必要があります返されることがあります
:1、データ形式を所定のテーブルアセンブリのデフォルト

{
  "code": 0,
  "msg": "",
  "count": 1000,
  "data": [{}, {}]
} 

参考資料

{
    "code": 0,
    "msg": "",
    "count": 1000,
    "data": [
        {
            "id": 10000,
            "username": "user-0",
            "sex": "女",
            "city": "城市-0",
            "sign": "签名-0",
            "experience": 255,
            "logins": 24,
            "wealth": 82830700,
            "classify": "作家",
            "score": 57
        }
    ]
}

2は、カスタムデータ形式を返し、それが所定のデータ形式に戻りたい、そして、応答がパラメータを利用することができ、例えば:

table.render({
  elem: '#demp'
  ,url: ''
  ,response: {
    statusName: 'status' //规定数据状态的字段名称,默认:code
    ,statusCode: 200 //规定成功的状态码,默认:0
    ,msgName: 'hint' //规定状态信息的字段名称,默认:msg
    ,countName: 'total' //规定数据总数的字段名称,默认:count
    ,dataName: 'rows' //规定数据列表的字段名称,默认:data
  } 
  //,…… //其他参数
});     

次のようにフォーマットは、上記指定されました:

{
  "status": 200,
  "hint": "",
  "total": 1000,
  "rows": []
} 

おすすめ

転載: blog.csdn.net/sinat_41632924/article/details/86611957