为什么我的全局requirejs var undefined?

时间:2017-03-27 12:37:37

标签: javascript requirejs edx

我有两个单独的申请。两者都使用jQuery和RequireJS。我想将应用程序A嵌入到应用程序B中,因此我将所需的HTML传输到应用程序B.应用程序B是edx-platform(https://github.com/edx/edx-platform)的一个实例。

到目前为止一切顺利,但第二个应用程序无法加载。首先,我有两个脚本标签与data-main,但它不起作用。所以我搜索了一下,发现了这个:https://stackoverflow.com/a/10839885

到目前为止我看起来很好,但我的全局requirejs变量未定义。在HTML edx-platform中使用以下代码调用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也是未定义的。

1 个答案:

答案 0 :(得分:0)

好的,我发现了为什么它是未定义的。 edX还加载了未定义所有这些变量的文件。

现在我需要找到一种方法来运行我的代码。

相关问题