我在让jQuery DataTables工作上遇到了很多麻烦。我一直在寻找很多地方,只是似乎找不到它的真相。
我通过Chrome developer工具收到的错误是:
$(.).DataTable不是函数
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 (由TypeScript生成):
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();
});
});发布于 2015-07-28 15:15:50
由于DataTables将自己声明为一个命名模块,因此在为require中的路径声明名称时,必须使用“datatable”名称。
在这里直播示例。归功于这里。
发布于 2015-07-16 18:53:16
造成错误的原因很可能是:
./dist/jquery-1.10.2.min.js)
或./dist/jquery.dataTables.min.js)
或jquery.dataTables.min.js的第一行应该包含插件版本。
方法DataTable()只在jQuery DataTables 1.10中可用。https://stackoverflow.com/questions/30654051
复制相似问题