【问题标题】:Spring thymleaf how to add th:href="@{}" from jquery datatableSpring thymeleaf 如何从 jquery 数据表中添加 th:href="@{}"
【发布时间】:2018-05-19 09:25:58
【问题描述】:

我正在尝试从 jquery 数据表添加一个 href 链接,但 thymleaf th:href="@{}" 在处理页面时没有被识别。这是我的代码。

 $("#categoriesTable").DataTable({

            "Processing":true,
            "ServerSide":true,
            "ajax": {"url": "/ajax/categories", "dataSrc": ""},
            "columns": [
                {"data": "id"},
                {"data": "name"},
                {"data": "description"},
                {"data": "create_at"},
                {"data": null,
                "render": function(data, type, row){
                    return '<a class="btn btn-primary btn-xs"  th:href="@{/category/'+data.id+'/edit}"  >Edit</a>'

                },
                    "targets": -1
                }
            ]
        });

【问题讨论】:

    标签: java jquery spring datatables thymeleaf


    【解决方案1】:

    您可以定义将保存上下文值并在呈现行时使用它的 javascript 变量

    <script th:inline="javascript>
        /*<![CDATA[*/
           var context = [[@{/}]];
        /*]]>*/
    </script>
    
    $("#categoriesTable").DataTable({
    
                "Processing":true,
                "ServerSide":true,
                "ajax": {"url": "/ajax/categories", "dataSrc": ""},
                "columns": [
                    {"data": "id"},
                    {"data": "name"},
                    {"data": "description"},
                    {"data": "create_at"},
                    {"data": null,
                    "render": function(data, type, row){
                        return '<a class="btn btn-primary btn-xs"  href=""+context+"/"+data.id+"/edit">Edit</a>'
                        },
                        "targets": -1
                    }
                ]
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      • 2023-03-31
      • 2014-12-07
      • 1970-01-01
      • 2021-04-06
      • 2018-05-30
      • 1970-01-01
      相关资源
      最近更新 更多