use requirejs load jquery plugs datatables ,have an error

221 Views Asked by At

i use requirejs load datatable plug,i got an error $().dataTable()is not function,

this is my js code:

define(function() {
requirejs.config({
    baseUrl: "/Scripts",
    paths: {
        "jquery": "/Libs/jquery.min"
        "jquery.datatable": "/Libs/dataTable/js/jquery.dataTables.min"
    },
    map: {
        "*": {
            "css": "/Libs/cssjs/css.js"
        }
    },
    shim: {
        "jquery": {
            exports: "$"
        },
        "jquery.datatable":"jquery"
    },
    waitSeconds: 15,
});})

this is page js

define(["jquery.datatable"], function() {
$(function() {
    $("#example").dataTable();
});

});

when i run it ,i got an error on my console :

TypeError: $(...).dataTable is not a function

jquery version is v1.11.0

DataTables version is v1.10.7

RequireJS version is v2.1.11

can u help me? thanks

1

There are 1 best solutions below

0
On

i solved this question update the requirejs config like this :

requirejs.config({
baseUrl: "/Scripts",
paths: {
    "jquery": "/Libs/jquery.min",
    "datatables": "/Libs/dataTable/js/jquery.dataTables.min"
},
map: {
    "*": {
        "css": "/Libs/cssjs/css.js"
    }
},
shim: {
    "jquery": {
        exports: "$"
    },
    "datatables":"jquery"
},
waitSeconds: 15,

});})

Note: the datatables's path,the paths name must be datatables.