我试图在DataTables中使用简单的简单的RequireJS。但是我不知道如何设置我的main.js文件。这就是我所拥有的:
require.config({
paths: {
modernizr: 'libs/custom.modernizr',
jquery: '../components/jquery/jquery',
datatables: '../components/datatables/media/src/DataTables'
},不过,只要加上
require(["datatables"]), function (whatever) {... });我总是收到这个错误:
Error: Module name "api.static.js" has not been loaded yet for context: _我尝试使用"shim“来使jquery成为datatable的依赖项,但我得到了相同的错误。有人知道如何使用requireJS建立一个非常简单的数据表吗?
更新:
下面是完整的main.js文件:
require.config({
paths: {
jquery: '../components/jquery/jquery',
datatables: '../components/datatables/media/src/DataTables'
},
shim: {
"datatables": ['jquery']
}
});
require(["jquery", "datatables"], function () {
$('#test').dataTable( {
"aaData": [
['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C']
],
"aoColumns": [
{ "sTitle": "Engine" },
{ "sTitle": "Browser" },
{ "sTitle": "Platform" },
{ "sTitle": "Version" },
{ "sTitle": "Grade" }
]
});
});这是准确的错误信息。我尝试使用多个版本的Jquery并在多个浏览器中使用,并且总是收到相同的消息:

如果重要的话,我使用zurb基础yo生成器构建了这个main.js,然后使用
bower install --save jquery#1.11.0
bower install --save datatables 发布于 2014-01-27 00:13:49
我想通了。问题是我在这行中指向了可数据变量。
datatables: '../components/datatables/media/src/DataTables' 文件"DataTables.js.“这是个错误的文件。它应该指向这样的"jquery.dataTables.js“:
datatables: '../components/datatables/media/js/jquery.dataTables'希望这能帮助人们在未来避免这种困惑。
https://stackoverflow.com/questions/21358675
复制相似问题