问题描述
我想在我的应用程序中使用 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']
}
});
在我的应用中:
define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
$('div').addClass('white');
});
不幸的是,这只适用于普通的 addClass
而不是来自 jQuery UI 的动画.
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.
这篇关于我如何在 requirejs 中使用 jquery ui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!