我一直在尝试从http://net.tutsplus.com/tutorials/javascript-ajax/building-a-scalable-app-with-backbone-js/扩展模板应用程序。在以下实现中,我遇到了“未捕获的ReferenceError:jQuery is not defined”。有人能告诉我是什么问题导致的吗?
config.js
// Set the require.js configuration for your application.
require.config({
// Initialize the application with the main application file
deps: ["main"],
urlArgs: "bust=" + (new Date()).getTime(),
waitSeconds: 15,
paths: {
// JavaScript folders
libs: "../assets/js/libs",
plugins: "../assets/js/plugins",
// Libraries
//jquery: "../assets/js/libs/jquery",
jquery: "http://code.jquery.com/jquery-1.7.min",
jquerycookie: "../assets/js/libs/jquery.cookie",
jqueryDataTables: "../assets/js/libs/jquery.dataTables.min",
jqueryValidate: "../assets/js/libs/jquery.validate",
jqueryValidateUnobtrusive: "../assets/js/libs/jquery.validate.unobtrusive",
underscore: "../assets/js/libs/underscore",
backbone: "../assets/js/libs/backbone",
highcharts: "../assets/js/libs/highcharts/highcharts",
highstock: "../assets/js/libs/highcharts/highstock",
easyXDM: "../assets/js/libs/easyXDM/easyXDM.min",
dateFormat: "../assets/js/libs/date.format",
// Shim Plugin
use: "../assets/js/plugins/use"
},
priority: [
'jquery',
'jquerycookie',
'jqueryValidate',
'jqueryValidateUnobtrusive',
'underscore',
'easyXDM',
"highcharts",
"highstock",
"dateFormat"
],
use: {
backbone: {
deps: ["use!underscore", "jquery"],
attach: "Backbone"
},
jqueryDataTables: {
deps: ["jquery"]
},
jqueryValidate: {
deps: ["jquery"]
},
jqueryValidateUnobtrusive: {
deps: ["jquery", "jqueryValidate"]
},
jquerycookie: {
deps: ["jquery"]
},
underscore: {
attach: "_"
},
highcharts: {
exports: 'Highcharts'
},
highstock: {
exports: 'highstock'
}
}
});
main.js
require([
"namespace",
// Libs
"jquery",
"jqueryDataTables",
"use!backbone",
'jquerycookie',
'jqueryValidate',
'jqueryValidateUnobtrusive',
'highcharts',
// Modules
"modules/tricklebot",
"modules/home",
"modules/dashboard",
"modules/profile",
"modules/transactions",
"modules/analysis",
"modules/signup",
],
function(namespace, $, jqDT, Backbone,
jqCookie, jqValidate, jqValidateUnobtrusive, highcharts,
tricklebot, Home, Dashboard, Profile, Transactions, Analysis, Signup) {
......
......
2条答案
按热度按时间c3frrgcw1#
我认为您正在遵循一个过时的教程,require.js配置中的
use
和priority
已被替换为shim
,请检查以下内容:https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0x8goxv8g2#
现在有一种更简单的方法来加载普通的JS文件,使用更新的RequireJS --一种避免了所有路径、Map、shim的无意义的方法:
使用不带.js的JavaScript计划文件会使它像模块ID一样受到所有“Map”和“路径”修改的影响,但当/如果普通JS文件不是模块时,仍然不会抱怨。
模块不会在后续的加载中重新加载,因为它们从第一次开始就被缓存了。