未捕获的 TypeError:this.each 不是函数

在尝试创建内联数据表时,我不断遇到此错误。我什至尝试直接复制文档中的示例代码!下面给出的代码是工作数据表代码:


<html>

<script type="text/javascript" src="https://cdn.datatables.net/r/bs-3.3.5/jqc-1.11.3,dt-1.10.8/datatables.min.js"></script>

    <script type="text/javascript" src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>

    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.1/js/dataTables.buttons.min.js"></script>

    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>

    <script type="text/javascript">


        var editor; // use a global for the submit and return data rendering in the examples

$(document).ready(function() {


 

    $('#example').DataTable( {

        ajax: {url:'https://api.myjson.com/bins/gcx26',

            crossDomain : true},


        order: [[ 1, 'asc' ]],

        columns: [

            { data: "first_name" },

            { data: "last_name" },

            { data: "position" },

            { data: "office" },

            { data: "start_date" },

            { data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }

        ]

    } );

} );

    </script>

<body>

<table id="example" class="display" cellspacing="0" width="100%">

        <thead>

            <tr>

                <th></th>

                <th>First name</th>

                <th>Last name</th>

                <th>Position</th>

                <th>Office</th>

                <th width="18%">Start date</th>

                <th>Salary</th>

            </tr>

        </thead>

    </table>

</body>

</html>


慕斯王
浏览 93回答 1
1回答

繁花不似锦

我发现我们不能使用$.fn.dataTable-editor.Editor,正如@mplungjan 所说,它所做的只是从$fn.database. 相反,我们必须从网站本身下载一个依赖项:“Editor-1.9.2/js/dataTables.editor.js”。在本地下载文件后,可以运行代码。这是代码的新的和改进的工作版本:<!DOCTYPE html><html><link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jqc-1.12.4/dt-1.10.20/b-1.6.1/sl-1.3.1/datatables.min.css"/><link rel="stylesheet" type="text/css" href="Editor-1.9.2/css/editor.dataTables.css">&nbsp;<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jqc-1.12.4/dt-1.10.20/b-1.6.1/sl-1.3.1/datatables.min.js"></script><script type="text/javascript" src="Editor-1.9.2/js/dataTables.editor.js"></script><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script><script type="text/javascript" src="https://cdn.datatables.net/r/bs-3.3.5/jqc-1.11.3,dt-1.10.8/datatables.min.js"></script><script type="text/javascript" src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>&nbsp;<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.1/js/dataTables.buttons.min.js"></script>&nbsp;<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script><script type="text/javascript" src="Editor-1.9.2/js/dataTables.editor.js"></script>&nbsp; &nbsp; <script type="text/javascript">&nbsp; &nbsp; &nbsp; &nbsp; var editor; // use a global for the submit and return data rendering in the examples&nbsp;$(document).ready(function() {&nbsp; &nbsp; editor = new $.fn.dataTable.Editor( {&nbsp; &nbsp; &nbsp; &nbsp; ajax: {url:'https://api.myjson.com/bins/gcx26',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; crossDomain : true},&nbsp; &nbsp; &nbsp; &nbsp; table: "#example",&nbsp; &nbsp; &nbsp; &nbsp; fields: [ {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: "First name:",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: "first_name"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: "Last name:",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: "last_name"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: "Position:",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: "position"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: "Office:",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: "office"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: "Extension:",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: "extn"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: "Start date:",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: "start_date",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "datetime"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: "Salary:",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: "salary"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; ]&nbsp; &nbsp; } );&nbsp;&nbsp; &nbsp; // Activate an inline edit on click of a table cell&nbsp; &nbsp; &nbsp; $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; editor.inline( this );&nbsp; &nbsp; &nbsp; &nbsp; } );&nbsp;&nbsp; &nbsp; $('#example').DataTable( {&nbsp; &nbsp; &nbsp; &nbsp; dom: "Bfrtip",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ajax: {url:'https://api.myjson.com/bins/gcx26',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; crossDomain : true},&nbsp; &nbsp; &nbsp; &nbsp; order: [[ 1, 'asc' ]],&nbsp; &nbsp; &nbsp; &nbsp; columns: [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: null,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; defaultContent: '',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; className: 'select-checkbox',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; orderable: false&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { data: "first_name" },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { data: "last_name" },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { data: "position" },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { data: "office" },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { data: "start_date" },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }&nbsp; &nbsp; &nbsp; &nbsp; ],&nbsp; &nbsp; &nbsp; &nbsp; select: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; style:&nbsp; &nbsp; 'os',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selector: 'td:first-child'&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; buttons: [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { extend: "create", editor: editor },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { extend: "edit",&nbsp; &nbsp;editor: editor },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { extend: "remove", editor: editor }&nbsp; &nbsp; &nbsp; &nbsp; ]&nbsp; &nbsp; } );} );&nbsp; &nbsp; </script><body><table id="example" class="display" cellspacing="0" width="100%">&nbsp; &nbsp; &nbsp; &nbsp; <thead>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th></th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>First name</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Last name</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Position</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Office</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th width="18%">Start date</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Salary</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; </thead>&nbsp; &nbsp; </table></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript