Javascript 面条

Javascript Moodle

您好,我对 Moodle 还很陌生。我一直在尝试测试我的 Javascript 运行 是否无济于事。这是我拥有的:

在/videojs/amd/src中我用一个简单的命令

创建了一个test.js文件
define(['jquery'], function() {
    return {
        init: function() {
            // Put whatever you like here. $ is available
            // to you as normal.
                alert("It changed!!");
        }
    };
});

然后我 g运行t 文件,一切都成功了,并且缩小了。但是当我转到该页面时,它没有 运行。现在我读 Moodle's Javascript Doc 并且看到它说

The idea here is that we will run the 'init' function from our (PHP) code to set things up. This is called from PHP like this...

我在哪里调用这个 PHP?

在你正在输出的页面的某处,你需要添加这样的调用:

$PAGE->requires->js_call_amd('PLUGINTYPE_videojs/test', 'init);

从您的示例中并不完全清楚您正在创建哪种类型的插件,因此无论您正在创建哪种类型 (https://docs.moodle.org/dev/Plugin_types),您都需要将其放在您站点的适当子目录中(例如 /mod/videojs、/local/videojs 等),然后添加某种 PHP 脚本作为插件的入口点,并从那里调用 js_call_amd 函数。