我如何将jquery ui与requirejs一起使用 [英] How do I use jquery ui with requirejs
问题描述
我想在我的应用程序中使用jQuery UI的addClass
函数.
I want to use jQuery UI's addClass
function in my application.
此外,我使用的是普通的jQuery,下划线,主干,它们都与requirejs一起分层.
Beside I am using the normal jQuery, underscore, backbone all tiered together with requirejs.
我已经这样配置jQuery UI:
I have configured jQuery UI like this:
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']
}
});
在应用程序中,我这样做:
In the application I do:
define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
$('div').addClass('white');
});
不幸的是,这只会执行普通的addClass
而不是来自jQuery UI的动画addClass
.
Unfortunately this only does the normal addClass
not the animated one from jQuery UI.
PS:我使用完整的jQuery版本.
PS: I use the full jQuery edition.
推荐答案
您需要包含jquery-ui:
You need to include jquery-ui:
define(['jquery-ui', 'backbone'], function() {
$('div').addClass('white');
});
jquery应该自动需要,因为它是jquery-ui的依赖项
jquery should be required automatically as it is a dependency of jquery-ui
此外,这些脚本均未返回任何内容,但它们的变量已分配给window对象.无需分配它们.
Additionally, none of these scripts return anything, but their variables are assigned to the window object. No need to assign them.
这篇关于我如何将jquery ui与requirejs一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!