【发布时间】:2016-02-11 17:11:52
【问题描述】:
我一直无法让 jQueryUI 正常工作。在我尝试添加 jQueryUI 之前,单独使用 jQuery 就可以了。
使用下面的代码,我目前在 chrome 中得到“TypeError: jQuery is not a function(...)”,这很奇怪,考虑到 jquery 在 require.config 文件中被标记为依赖项。
从 .ts 到 .js 的编译没有错误。
initApp.ts:
/// <reference path="../../../typings/jqueryui/jqueryui.d.ts"/>
import * as jQuery from "jquery"; //Works completely fine
import * as jQueryUI from "jquery-ui"; //Can't even find the module unless
//d.ts file is modified
编译成js:
define(["require", "exports", "jquery-ui"], function (require, exports, jQuery) {...}
jqueryui.d.ts:
/// <reference path="../jquery/jquery.d.ts"/>
declare module JQueryUI { <unmodified code>}
//Added this declare
declare module "jquery-ui" {
export = jQuery;
}
Require.config.js:
require.config({
baseUrl: "./components/",
paths: {
"jquery": "./javascripts/lib/jquery-2.1.4",
"jquery-ui": "./javascripts/lib/jquery-ui",
"go": "./javascripts/lib/go-debug"
},
shim: {
"jquery": {
exports: "jQuery",
},
"jquery-ui": {
//exports: "jQuery", //Adding this line doesn't fix the problem
deps: ["jquery"],
}
},
});
require(["./javascripts/initApp"]);
目录树:
typings/
jquery/
jquery.d.ts
jqueryui/
jqueryui.d.ts
web/
components/
javascripts/
lib/
jquery-2.1.4.js
jquery-ui.js
require.js
initApp.js
initApp.ts
require.config.js
完整 d.ts 文件的链接:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jquery/index.d.ts (jquery V3.3)
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jqueryui/index.d.ts (QueryUI V1.12)
任何帮助将不胜感激
【问题讨论】:
-
我已删除您添加到问题中的解决方案。本网站的编辑做法是,必须将解决方案作为答案发布,以便人们可以独立从问题中对解决方案进行投票。所以你应该发布你的解决方案作为答案。您可以返回问题的编辑历史,找到添加解决方案的编辑,单击“源”按钮,复制源并将其粘贴到答案表单中。最多需要 2 分钟。
标签: jquery jquery-ui typescript requirejs