1

私は Require.js に不慣れで、助けが必要です (私を信じてください、私はたくさん検索しますが、まだ迷っています)。

私の開発環境では、ファイルをキャッシュする必要がないようにする必要があります。わかりました、私はすでに周りを検索して、この解決策を見つけまし

しかし、それをrequire.configコードに入れると、jQueryなどからの参照がすべて失われました...
エラーは次のとおりです。

Uncaught TypeError: undefined is not a function 
Uncaught ReferenceError: jQuery is not defined 

私のコードに何か問題があると思いますが、何が (依存関係、参照...) わかりません。

main.js で:

requirejs.config({
 "urlArgs": "bust=" + (new Date()).getTime()
 "baseUrl": "js/app",
 "paths": {
    "doctorWorklist": "doctor-worklist",
    "jquery": "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min",
    "bootstrap": "../lib/bootstrap.min",
    "app": "app"
 }
});

// Load the main app module to start the app
requirejs(["app"]);

app.js で

define( ['jquery', 'bootstrap'], function( $ ) {
 //my code here.
});

助言がありますか ?
そして下手な英語でごめんなさい。:D

-- 9月18日更新。了解!私のようにrequire.jsを使い始めた人にとって、上記に関連するエラーはmain.jsにありました

私の目的では、main.js のコードは次のようにする必要があります。

requirejs.config({
"urlArgs": "bust=" + Math.random(),
"baseUrl": "js/app",
"paths": {
    "doctorWorklist": "doctor-worklist",
    "jquery": "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min",
    "dataTables": "http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min",
    "bootstrap": "../lib/bootstrap.min",
    "bootstrapDatepicker": "../lib/bootstrap-datepicker.min",
    "bootstrapSelect": "../lib/bootstrap-select.min",
    "jPlayer": "../lib/jquery.jplayer.min",
    "countdown": "../lib/jquery.countdown.min",
    "countdownBR": "../lib/jquery.countdown-pt-BR.min",
    "googleapi": "../lib/googlecharts-api",
    "onrad": "onrad"
}
});

// Load the main app module to start the app
requirejs(["jquery"], 
function($, jQuery) {
    var jQuery = $;
    // This moment, jQuery is completely loaded.
    // Time to require external libs with jQuery dependencies
    requirejs(
        [
            "dataTables",
            "bootstrap", 
            "bootstrapDatepicker", 
            "bootstrapSelect"                
        ]
    , function($, jQuery) {
        // External libs loaded !
        // Time to required my app code
        requirejs(["countdown", "countdownBR", "onrad"]);
    });
}
);

誰かに役立つことを願っています。

4

0 に答える 0