简体   繁体   English

使用jquery-ui小部件

[英]Using a jquery-ui widget

I want to use the sortable widget of jquery-ui. 我想使用jquery-ui的可排序小部件。 I installed jquery-ui with: 我安装了jquery-ui与:

bower install jquery-ui

Im using require.js. 我正在使用require.js。 I have added a section of jquery-ui/sortable: 我添加了jquery-ui / sortable的一部分:

paths: {
    ...
    'jquery.ui/sortable': 'bower_components/jquery.ui/ui/widgets/sortable'
    ...

In my module I import with: 在我的模块中导入:

define(
[
    'jquery.ui/sortable',
    ...
],
function(
    sortable,
    ...
) {

This will give me loads of errors because sortable.js then tries to import its dependencies. 这将给我带来很多错误,因为sortable.js然后尝试导入其依赖项。 The only way I could get it working is to add a path for every dependency of 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',

This seems like a terribly arduous way of doing this. 这似乎是一种极其艰巨的方式。 Also 'data', 'ie', 'version' and 'widget' only work if I don't namespace them. 如果我没有命名空间,那么“数据”,“即”,“版本”和“小部件”也只能工作。

Is this the correct way to use a jquery-ui widget? 这是使用jquery-ui小部件的正确方法吗?

If all the modules you ever refer to are ultimately under bower_components/jquery.ui/ui/widgets/ , then you could use a map instead of having a paths that lists each and every module: 如果您曾经引用​​的所有模块最终都在bower_components/jquery.ui/ui/widgets/ ,那么您可以使用map而不是包含列出每个模块的paths

map: {
  "*": {
    "jquery.ui": "bower_components/jquery.ui/ui/widgets"       
  }
}

This should map every request to jquery.ui/x to bower_components/jquery.ui/ui/widgets . 这应该jquery.ui/x每个请求映射到bower_components/jquery.ui/ui/widgets Because a map transforms a module name to another module name, then any module in bower_components/jquery.ui/ui/widgets that imports from .. will get a module from bower_components/jquery.ui/ui . 由于地图转换模块名到另一个模块名称,然后在任何模块bower_components/jquery.ui/ui/widgets ,从进口..会得到一个模块bower_components/jquery.ui/ui

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM