2017-05-18 31 views
0

にDatatables.net https://datatables.net/examples/advanced_init/length_menu.html の文書を1として、私はそれがだ、インラインで多次元配列を使用する方法thymeleaf 3

<script th:inline="javascript"> 
$(document).ready(function() { 
    $('#example').DataTable({ 
    "lengthMenu": [[10, 25, 50, [[${rowTotal}]]], [10, 25, 50, "All"]] 
    }); 
}); 
</script> 

しかし、レンダリングに、私のthmyeleafテンプレートにデータテーブルの実装にいくつかの設定を記述する必要があるのjavascriptそのようなエラーを私に与えてくれた。

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "10, 25, 50, -1], [10, 25, 50, 'All'" (template: "customer/customerlist" - line 237, col 21) 

そしてthymeleafでこの文書を読んで、それは When inlining, if the expression between [[...]] is not a valid Standard Expression, it is output without modification, including the double-brackets. https://github.com/thymeleaf/thymeleaf/issues/22を言われています。

この問題を解決するにはどうすればよいですか?

+0

あなたは何をサーバ側からthymeleafテンプレートに渡していますか?私は普通のjavascriptしか見ません。それをjsファイルに入れてhtmlファイルに入れてください –

+0

編集された質問 -1 - [[$ {rowTotal}]] –

答えて

2

まあ、私はそれがタイメリーフ2でどのように機能するのか分かりませんでした。一番簡単な変更は、それを別の方法でフォーマットすることです。このような何か:

<script th:inline="javascript"> 
$(document).ready(function() { 
    $('#example').DataTable({ 
    "lengthMenu": [ 
     [10, 25, 50, -1], 
     [10, 25, 50, "All"] 
    ] 
    }); 
}); 
</script> 

それがあなたに合っていない場合、あなたはそれ自身のjavascriptのブロックにデータテーブルの定義を分割し、th:inline="none"を使用するか、またはそれ自身の外部のJavaScriptファイルに移動することができます。 (なぜこの場合にはth:inline="javascript"を使用していますか?)

+0

うわー、それは魅力のように機能します。 ありがとう@Metriods 私はjavascriptを使用しています [http://datatables.net/]でサポートされているExcel、pdfプラグインの合計行とメッセージを渡す必要があるためです。 –