[英]Require.js Shim for loading JQuery UI and other JQuery Packages
[英]require.js with jquery ui, not finding jquery
使用Require.js加载jquery-ui给我带来了问题-jquery-ui的依赖项看不到m起作用。 这是错误:
未捕获的TypeError:无法读取未定义的属性'ui'
这是两个文件:
main.js
require.config({
baseUrl: '/git-cake-skeleton/js',
paths: {
'jquery': 'lib/jquery-1.10.2',
'jqueryui': 'lib/jquery-ui-1.10.3.min',
'bootstrap': 'lib/bootstrap.min'
},
shim: {
'jqueryui': {
exports: '$',
deps: ['jquery']
},
'bootstrap': {
deps: ['jquery']
}
} });
require([
'jquery',
'widgets/demowidget'
], function ($) {
$(document).ready(function() {
// This is where we bind our widgets to stuff on the page. All the real logic happens inside widgets!
$(".app-js-demowidget").demowidget();
});
} );
demowidget.js
// Example of simple plugin inside Require.js framework
define(['jquery', 'jqueryui'], function ($) {
$.widget('skeleton.demowidget', {
options: {
},
_init: function() {
this.element.click(function(e){
alert('Hello world');
});
}
});
});
文件结构:
|-js
| main.js
|---lib
| bootstrap.min.js
| jquery-1.10.2.js
| jquery-ui-1.10.3.min.js
| require.js
|---widgets
| demowidget.js
编辑:按预期方式,在demowidget.js中用'bootstrap'切换'jqueryui'会产生以下错误:
Bootstrap需要jQuery
您首先需要定义jquery依赖项:
define('jquery', [], function () { return root.jQuery; });
然后,您可以根据jQuery使用“ jquery”加载其他库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.