如何在requirejs中使用jquery ui

bod*_*ser 39 javascript jquery-ui requirejs

我想addClass在我的应用程序中使用jQuery UI的功能.

除了我使用正常的jQuery,下划线,主干与requirejs一起分层.

我已经像这样配置了jQuery UI:

require.config({

    deps: ["main"],

    paths: {
        "text": "lib/text"
        , "jquery": "lib/jquery"
        , "jquery-ui": "lib/jquery-ui"
        , "underscore": "lib/underscore"
        , "backbone": "lib/backbone"
        , "bootstrap": "lib/bootstrap"
        , "templates": "../templates"
    },

    shim: {
        "jquery-ui": {
            exports: "$",
            deps: ['jquery']
        },
        "underscore": {
            exports: "_"
        },
        "backbone": {
            exports: "Backbone",
            deps: ["underscore", "jquery"]
        },
        "bootstrap": ['jquery']
    }

});
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中:

define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
    $('div').addClass('white');
});
Run Code Online (Sandbox Code Playgroud)

不幸的是,这只是普通addClass而不是来自jQuery UI的动画.

PS:我使用完整的jQuery版本.

Aus*_*tin 34

你需要包含jquery-ui:

define(['jquery-ui', 'backbone'], function() {
    $('div').addClass('white');
});
Run Code Online (Sandbox Code Playgroud)

应该自动要求jquery,因为它是jquery-ui的依赖项

此外,这些脚本都不会返回任何内容,但它们的变量将分配给窗口对象.无需分配它们.