Spring thymleaf, как добавить th: href = "@ {}" из jquery datatable - PullRequest
0 голосов
/ 19 мая 2018

Я пытаюсь добавить ссылку href из jquery datatable, но 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
                }
            ]
        });

1 Ответ

0 голосов
/ 20 мая 2018

Вы можете определить переменную 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
                }
            ]
        });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...