如何加载带有requirejs的Tempus Dominus Bootstrap 4(在Moodle中)? (错误:没有为datetimepicker定义调用)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何加载带有requirejs的Tempus Dominus Bootstrap 4(在Moodle中)? (错误:没有为datetimepicker定义调用)相关的知识,希望对你有一定的参考价值。
您好我在Moodle 3.5中使用requirejs来包含js文件,但是我遇到了Tempus Dominus Bootstrap 4的问题。
这是我的config.js
define([], function () {
window.requirejs.config({
paths: {
"moment": 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min',
"datetimepicker":'https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-4/5.0.0-alpha14/js/tempusdominus-bootstrap-4.min',
},
shim: {
'datetimepicker': {deps: ['jquery','moment'], exports: 'datetimepicker'},
}
});
});
datetimepicker.js
define(['myfolder/config', 'datetimepicker'], function(unused,datetimepicker) {
return datetimepicker;
}
);
myapp.js
define([
'jquery',
'myfolder/moment',
'myfolder/datetimepicker',
],
function ($,moment) {
function initManage() {
它抛出了错误:“没有为datetimepicker定义调用”;
怎么了?
答案
垫片必须是:
datetimepicker: { exports: "$.fn.datetimepicker" }
这是文件:config.js
define([], function () {
window.requirejs.config({
paths: {
"moment": M.cfg.wwwroot + '/admin/tool/myplugin/js/moment.min',
"moment-fr": M.cfg.wwwroot + '/admin/tool/myplugin/js/moment-fr',
"bootstrap": M.cfg.wwwroot + '/admin/tool/myplugin/js/bootstrap.bundle.min',
"datetimepicker":M.cfg.wwwroot + '/admin/tool/myplugin/js/tempusdominus-bootstrap-4',
},
shim: {
bootstrap: { deps: ["jquery"], exports: 'bootstrap'},
datetimepicker: { exports: "$.fn.datetimepicker" }
}
});
});
datetimepicker.js
define(['tool_myplugin/config', 'datetimepicker'], function(unused,datetimepicker) {
return datetimepicker;
});
和app.js
define([
'jquery',
'tool_myplugin/moment',
'tool_myplugin/bootstrap',
'tool_myplugin/datetimepicker'
],
function ($,moment) {
function initManage() {
$(document).ready(function () {
$('#datetimepicker1').datetimepicker({
format: 'HH:mm',
use24hours: true,
defaultDate: moment({hour: 9,minute:0})
});
...
以上是关于如何加载带有requirejs的Tempus Dominus Bootstrap 4(在Moodle中)? (错误:没有为datetimepicker定义调用)的主要内容,如果未能解决你的问题,请参考以下文章