我一直無法正常使jQueryUI正常工作。在我嘗試添加jQueryUI之前,讓jQuery單獨工作就好了。考慮到jquery在require.config文件中被標記爲依賴關係,所以我現在在chrome中得到了「TypeError:jQuery不是函數(...)」,這很奇怪。用Typescript和RequireJS導入jqueryui
從.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/jquery/index.d.ts https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/jqueryui/index.d.ts
任何幫助,將不勝感激
我已經刪除了你的解決方案已經添加到您的問題。這個網站的編輯實踐是這樣的,解決方案必須作爲答案發布,以便人們可以獨立地從問題上投票解決方案*。所以你應該發佈你的解決方案作爲答案。您可以回到問題的編輯歷史記錄中,找到編輯添加解決方案的位置,單擊「源」按鈕,複製源代碼並將其粘貼到答案表單中。最多需要2分鐘。 – Louis