如何在Moodle插件中包含带有requirejs的Tempus Dominus Bootstrap的moment.js?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Moodle插件中包含带有requirejs的Tempus Dominus Bootstrap的moment.js?相关的知识,希望对你有一定的参考价值。
您好我正在开发一个Moodle插件,其中我需要来自Tempus Dominus Bootstrap的datetimepicker
我使用了AMD requirejs。
在amd / src /我有config.js:
define([], function () {
window.requirejs.config({
paths: {
"moment": M.cfg.wwwroot + '/admin/tool/myplugin/js/moment.min',
"bootstrap": M.cfg.wwwroot + '/admin/tool/myplugin/js/bootstrap.bundle.min',
"datepicker": M.cfg.wwwroot + '/admin/tool/myplugin/js/bootstrap-datepicker141.min',
"datetimepicker": M.cfg.wwwroot + '/admin/tool/myplugin/js/tempusdominus-bootstrap-4.min',
},
shim: {
'moment': {exports: 'moment'},
'bootstrap': {exports: 'Bootstrap'},
'datepicker': { exports: 'datepicker'},
'datetimepicker': {deps: ['moment'], exports: '$.fn.datetimepicker'},
}
});
});
datetimepicker.js:
define(['tool_myplugin/config', 'datetimepicker'], function(unused,datetimepicker) {
return datetimepicker;
}
);
tool_myplugin.js:
define([
'jquery',
'tool_myplugin/moment',
'tool_myplugin/datepicker',
'tool_myplugin/datetimepicker',
],
function ($,moment) {
function initManage() {
$(document).ready(() => {
$('#datetimepicker1').datetimepicker({
format: 'HH:mm',
use24hours: true,
defaultDate: moment({hour: 9, minute: 00})
});
});
}
return {
init: function () {
initManage();
}
};
});
我在控制台中有这些错误:
Error: Tempus Dominus Bootstrap4's requires moment.js. Moment.js must be included before Tempus Dominus Bootstrap4's javascript. tempusdominus- bootstrap-4.min.js:20:9
.../tempusdominus-bootstrap-4.min.js:20:9
和
Error: No define call for datetimepicker
http://requirejs.org/docs/errors.html#nodefine
答案
我找到了解决方案:
这里是amd / src / moment.js
define(['tool_myplugin/config', 'moment'], function(unused,moment) {
window.moment = moment;
if (!window.moment) {
alert("moment ko");
}
return moment;
}
);
以上是关于如何在Moodle插件中包含带有requirejs的Tempus Dominus Bootstrap的moment.js?的主要内容,如果未能解决你的问题,请参考以下文章