嗨,我对 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!!");
}
};
});
然后我咕噜了文件,一切都成功了,并缩小了。但是当我进入该页面时它不会运行。现在我读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 函数。
关于JavaScript Moodle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44684299/