在 map属性中设置 '*': { 'jquery': 'lib/jquery',},jqueryUI的$ 找到不到了
1. 配置
require.config({ baseUrl: 'js/', paths: { 'jquery': 'lib/jquery', 'user': 'app/user', 'api': 'app/api', 'api2': 'app/api2', 'helper': 'app/helper', 'bootstrap': 'lib/bootstrap', 'modernizr': 'lib/modernizr', 'backbone': 'lib/backbone', 'underscore': 'lib/underscore', 'jquery-ui':'lib/jquery-ui', 'text': 'require/text', 'css': 'require/css', 'i18n': 'require/i18n' }, shim: { 'modernizr': { exports: 'Modernizr' }, 'bootstrap': { deps:['jquery'] }, 'jquery-ui':{ deps:['css!../css/jquery-ui.css', 'css!../css/jquery-ui.theme.css'] } }, config: { text: { onXhr: function(xhr, url) { //ajax请求执行了open方法,还没进行send方法之前,在这里可以设置http请求的请求头等信息 xhr.setRequestHeader('x-Requested-Width', 'XMLHttp'); }, onXhrComplete: function(xhr, url) { //ajax请求结束后执行 } }, i18n: { locale: typeof locale !== 'undefined' ? locale : 'zh' } }, map: { '*': { 'jquery': 'lib/jquery', }, 'api2': { 'jquery': 'lib/jquery2', } }})
2. 代码实现
var language = document.cookie.match(/language=([^;]+)/);var locale = 'zh-cn';if (language) { locale = language[1].split('_')[0]}require(['api', 'backbone', 'i18n!./nls/messages', 'jquery-ui', ], function(api, Backbone, i18n){ //点击打印用户信息 $('#userConsole').click(function() { api.getUser().then(function(user) { console.log(user); }); }) //点击加载用户信息(text插件测试) $('#userShow').click(function() { api.loadUser(); }) //点击弹框 $('#dialogShow').click(function() { $('#dialog').dialog(); }) //中英文切换\n $('#zn-en').text(i18n.edit )});
3. 报错信息
jquery-ui.js:31 Uncaught TypeError: Cannot read property 'ui' of undefined at jquery-ui.js:31 at Object.execCb (require.js:29) at $.check (require.js:18) at $.<anonymous> (require.js:23) at require.js:8 at require.js:23 at v (require.js:7) at $.emit (require.js:23) at $.check (require.js:19) at $.enable (require.js:23)