2017-03-27 76 views
0

我有兩個單獨的應用程序。兩者都使用jQuery和RequireJS。我想將應用程序A嵌入到應用程序B中,因此我將所需的HTML傳輸到應用程序B.應用程序B是edx-platform的一個實例(https://github.com/edx/edx-platform)。爲什麼我的全局requirejs var undefined?

到目前爲止好,但第二個應用程序不會加載。首先,我有兩個腳本標記與data-main,但它不起作用。所以我搜索,我發現這個:https://stackoverflow.com/a/10839885

我看起來不錯,但我的全局requirejs變量是未定義的。在HTML edx平臺調用RequireJS與此代碼:

<script> 
    window.baseUrl = "/static/"; 
    (function (require) { 
     require.config({ 
      baseUrl: window.baseUrl 
     }); 
    }).call(this, require || RequireJS.require); 
</script> 
<script type="text/javascript" src="/static/lms/js/require-config.js"></script> 
<script type="text/javascript"> 
    (function (require) { 
     require.config({ 
      paths: { 
       'js/courseware/courseware_factory': 'js/courseware/courseware_factory', 
       'draggabilly': 'js/vendor/draggabilly', 
       'js/courseware/toggle_element_visibility': 'js/courseware/toggle_element_visibility', 
       'js/courseware/course_home_events': 'js/courseware/course_home_events', 
       'js/courseware/link_clicked_events': 'js/courseware/link_clicked_events', 
       'moment': 'common/js/vendor/moment-with-locales', 
       'moment-timezone': 'common/js/vendor/moment-timezone-with-data', 
       'js/student_account/logistration_factory': 'js/student_account/logistration_factory', 
       'js/groups/views/cohorts_dashboard_factory': 'js/groups/views/cohorts_dashboard_factory', 
       'js/dateutil_factory': 'js/dateutil_factory', 
       'js/courseware/accordion_events': 'js/courseware/accordion_events', 
       'js/bookmarks/views/bookmark_button': 'js/bookmarks/views/bookmark_button', 
       'js/views/message_banner': 'js/views/message_banner', 
       'js/student_profile/views/learner_profile_factory': 'js/student_profile/views/learner_profile_factory' 
      } 
     }); 
    }).call(this, require || RequireJS.require); 
</script> 

我的代碼稍後將包含。我試圖運行一個簡單的console.log(requirejs),但它沒有奏效。從開發人員控制檯調用requirejs時也不確定。

回答

0

好的,我發現它爲什麼沒有定義。 edX也加載未定義所有這些變量的文件。

現在我需要找到一種方法讓我的代碼運行。