[英]Using a jquery-ui widget
我想使用jquery-ui的可排序小部件。 我安装了jquery-ui与:
bower install jquery-ui
我正在使用require.js。 我添加了jquery-ui / sortable的一部分:
paths: {
...
'jquery.ui/sortable': 'bower_components/jquery.ui/ui/widgets/sortable'
...
在我的模块中导入:
define(
[
'jquery.ui/sortable',
...
],
function(
sortable,
...
) {
这将给我带来很多错误,因为sortable.js然后尝试导入其依赖项。 我能使它工作的唯一方法是为sortable.js的每个依赖项添加一个路径:
'jquery.ui/sortable': 'bower_components/jquery.ui/ui/widgets/sortable',
'jquery.ui/mouse': 'bower_components/jquery.ui/ui/widgets/mouse',
'jquery.ui/scroll-parent': 'bower_components/jquery.ui/ui/scroll-parent',
'data': 'bower_components/jquery.ui/ui/data',
'ie': 'bower_components/jquery.ui/ui/ie',
'version': 'bower_components/jquery.ui/ui/version',
'widget': 'bower_components/jquery.ui/ui/widget',
这似乎是一种极其艰巨的方式。 如果我没有命名空间,那么“数据”,“即”,“版本”和“小部件”也只能工作。
这是使用jquery-ui小部件的正确方法吗?
如果您曾经引用的所有模块最终都在bower_components/jquery.ui/ui/widgets/
,那么您可以使用map
而不是包含列出每个模块的paths
:
map: {
"*": {
"jquery.ui": "bower_components/jquery.ui/ui/widgets"
}
}
这应该jquery.ui/x
每个请求映射到bower_components/jquery.ui/ui/widgets
。 由于地图转换模块名到另一个模块名称,然后在任何模块bower_components/jquery.ui/ui/widgets
,从进口..
会得到一个模块bower_components/jquery.ui/ui
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.