У меня есть сайт, разработанный в cakephp, позвоночник и requirejs.RequireJS использование пути в другом файле
В мой конфигурационный файл я сопоставил свой javascript и, если я вызвал jquery в этот файл, все работает нормально. Если я вызываю jquery в другой файл, дайте мне ошибку, что функция не указана, так как jquery не загружен.
Это мой fole работает отлично config.js:
require.config({
baseUrl: "/site.com/js/",
paths: {
// Aliases for libraries, so that we can change versions from here
jquery: "libs/jquery/jquery-2.0.2.min",
handlebars: "libs/backbone/template/handlebars",
lodash: "libs/backbone/template/lodash.min",
backbone: "libs/backbone/backbone-1.0.0.min",
less:"libs/less/less-1.4.0-beta.min",
helper:"app/helper",
jquery_cookie:"libs/jquery/plugin/jquery.cookie",
text:"libs/require/text-2.0.7"
},
shim: {
"lodash": { exports: '_' },
"handlebars": { exports: 'Handlebars' },
"jquery": { exports: '$' },
"backbone": {
//These script dependencies should be loaded before loading
//backbone.js
deps: ["helper", "lodash", "jquery"],
//Once loaded, use the global "Backbone" as the
//module value.
exports: "Backbone"
},
"jquery_cookie": {
deps: ["jquery"]
//,exports:"$"
},
"less": {
exports:"less"
}
}
// This is appended to every module loading request, for cache invalidation purposes
// comment it on production
, urlArgs: "bust=" + (new Date()).getTime()
});
require(["jquery"], function ($) {
$("body").empty();
});
Вместо если я пишу это в config.js
require.config({
baseUrl: "/site.com/js/",
paths: {
// Aliases for libraries, so that we can change versions from here
jquery: "libs/jquery/jquery-2.0.2.min",
handlebars: "libs/backbone/template/handlebars",
lodash: "libs/backbone/template/lodash.min",
backbone: "libs/backbone/backbone-1.0.0.min",
less:"libs/less/less-1.4.0-beta.min",
helper:"app/helper",
jquery_cookie:"libs/jquery/plugin/jquery.cookie",
text:"libs/require/text-2.0.7"
},
shim: {
"lodash": { exports: '_' },
"handlebars": { exports: 'Handlebars' },
"jquery": { exports: '$' },
"backbone": {
//These script dependencies should be loaded before loading
//backbone.js
deps: ["helper", "lodash", "jquery"],
//Once loaded, use the global "Backbone" as the
//module value.
exports: "Backbone"
},
"jquery_cookie": {
deps: ["jquery"]
//,exports:"$"
},
"less": {
exports:"less"
}
}
// This is appended to every module loading request, for cache invalidation purposes
// comment it on production
, urlArgs: "bust=" + (new Date()).getTime()
});
И переместить вызов JQuery в default.ctp получить я ошибка функции undefined, потому что не загружает jQuery, я думаю.
default.ctp
require(["jquery"], function ($) {
$("body").empty();
});
Почему я не могу использовать JQuery в deafult.ctp? Мне нужно сопоставить все файлы? Я так не думаю, может кто-нибудь мне помочь? Thanks
это еще проблема? Если да, как вы победили? – w3jimmy