您好,我正在开发一个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
答案 0 :(得分:0)
我找到了解决方法:
这是amd / src / moment.js
define(['tool_myplugin/config', 'moment'], function(unused,moment) {
window.moment = moment;
if (!window.moment) {
alert("moment ko");
}
return moment;
}
);