2015-06-04 31 views
3

我在獲取jQuery DataTable的時候遇到了很多麻煩。我一直在尋找很多地方,似乎無法深入到底。

我通過Chrome開發者工具收到的錯誤是:

$(...)數據表不是一個函數

app.js:

requirejs.config({ 
    "baseUrl": "../Scripts", 
    "paths": { 
     app: "./app", 
     essentials: "./dist/essentials.min", 
     jquery: "./dist/jquery-1.10.2.min", 
     "jquery.bootstrap": "./dist/bootstrap.min" 
     "jquery.dataTables": "./dist/jquery.dataTables.min", 
     "jquery.dataTables.bootstrap": "./dist/jquery.dataTables.bootstrap.min" 

    }, 
    "shim": { 
     "essentials": ["jquery"], 
     "jquery.dataTables": ["jquery"], 
     "jquery.dataTables.bootstrap": ["jquery.dataTables"], 
     "jquery.bootstrap": ["jquery"] 
    } 
}); 

// Load the main app module to start the app 
requirejs(["app/main"]); 

main.js(未使用):

require(["jquery"], function ($) { 
    $(function() { 
    }); 
}); 

Create.js(從打字稿生成):

define(["require", "exports", "../../Shared/ModalHelper"], function (require, exports, Helper) { 
    require(["jquery", "essentials", "jquery.bootstrap", "jquery.dataTables", "jquery.dataTables.bootstrap"], function ($) { 
     function initilializeTables() { 
      var attrSelectDataTable = $('#selectAttrsTable').DataTable({ 
       paging: true, 
       bInfo: true, 
       "columnDefs": [ 
        { "orderable": false, "targets": 0 } 
       ], 
       scrollY: 400 
      }); 
      var attrPreviewDataTable = $('#selectedAttrsTable').DataTable({ 
       paging: true, 
       bInfo: true, 
       "columnDefs": [ 
        { "orderable": false, "targets": 0 }, 
        { "orderable": false, "targets": 5 } 
       ], 
       scrollY: 400 
      }); 

     } 

     initilializeTables(); 

    }); 
}); 

回答

0

很可能是錯誤的原因是:

  • 缺少jQuery庫(./dist/jquery-1.10.2.min.js

    OR

  • 缺少jQuery的數據表插件(./dist/jquery.dataTables.min.js

    OR

  • jQuery的數據表的版本是1.9.x的或更低。第一行jquery.dataTables.min.js應該包含插件版本。

    方法DataTable()僅在jQuery DataTables 1.10中可用。

1

由於數據表聲明自己爲一個名爲模塊中,「數據表」的名稱具有路徑聲明的名稱時需要配置使用。

Live example here。信貸到here