jQuery DataTable从我的json文件中设置语言

时间:2016-11-22 04:03:34

标签: jquery datatables

我有jQuery DataTable,我想要设置语言。 我可以用3种方式做到这一点

1

"language": {
 "url": "//cdn.datatables.net/plug-ins/1.10.12/i18n/Russian.json"
           },

2。

 "language": {
     "decimal":        "",
     "emptyTable":     "No data available in table",>         "info":           "Showing _START_ to _END_ of _TOTAL_ entries",
     "infoEmpty":      "Showing 0 to 0 of 0 entries",
     "infoFiltered":   "(filtered from _MAX_ total entries)",
     "infoPostFix":    "",
     "thousands":      ",",
     "lengthMenu":     "Show _MENU_ entries",
     "loadingRecords": "Loading...",
     "processing":     "Processing...",
     "search":         "Search:",
     "zeroRecords":    "No matching records found",
     "paginate": {
         "first":      "First",
         "last":       "Last",
         "next":       "Next",
         "previous":   "Previous"
     },
     "aria": {
         "sortAscending":  ": activate to sort column ascending",
         "sortDescending": ": activate to sort column descending"
     }
  1. 使用配置创建russian.json文件并将其包含在内

    "language": { "url": "/russian.json" },

  2. 但有3种方法对我不起作用。我该怎么办?

1 个答案:

答案 0 :(得分:-1)

我已尝试过你的第二种方式,@ user5620472,它有效:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jQuery DataTable language</title>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var data = [
                {
                    "name": "Tiger Nixon",
                    "position": "System Architect",
                    "salary": "$3,120",
                    "start_date": "2011/04/25",
                    "office": "Edinburgh",
                    "extn": "5421"
                },
                {
                    "name": "Garrett Winters",
                    "position": "Director",
                    "salary": "$5,300",
                    "start_date": "2011/07/25",
                    "office": "Edinburgh",
                    "extn": "8422"
                }
            ];
            $('#myTable').DataTable({
                data: data,
                columns: [
                    { data: 'name' },
                    { data: 'position' },
                    { data: 'salary' },
                    { data: 'office' }
                ],
                "language": {
                    "lengthMenu": "Дисплей _MENU_ записей на странице",
                    "zeroRecords": "Nothing found - sorry",
                    "info": "Showing page _PAGE_ of _PAGES_",
                    "infoEmpty": "No records available",
                    "infoFiltered": "(filtered from _MAX_ total records)"
                }
            });
        });
    </script>
</head>
<body>
    <table id="myTable">
    </table>
</body>
</html>