RequireJS + Bootstrap 日期选择器 + 语言环境文件
RequireJS + Bootstrap Datepicker + Locale Files
我正在将我们的项目切换到模块。所以大多数事情都在工作,但有些组件有一些问题。主要问题似乎是本地化文件。
如果我有这个例子的解决方案,我可以解决我项目中的其他问题。
我正在使用 Bootstrap 来自此处的日期选择器 https://bootstrap-datepicker.readthedocs.org/
Requirejs 配置:
require.config({
baseUrl: "Scripts",
paths: {
... some more like jquery and jquery-ui...
"bootstrap-datepicker": "bootstrap-datepicker",
"bootstrap-datepicker-de": "./locales/bootstrap-datepicker.de",
}
shim: {
'bootstrap-datepicker-de': ['bootstrap-datepicker']
}
});
App.ts:
... some more imports like jquery and jquery-ui...
import "bootstrap-datepicker";
import "bootstrap-datepicker-de";
... init App ...
bootstrap-datepicker.de.js
; (function ($) {
$.fn.datepicker.dates['de'] = {
days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
daysShort: ["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"],
daysMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
monthsShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
today: "Heute",
monthsTitle: "Monate",
clear: "Löschen",
weekStart: 1,
format: "dd.mm.yyyy"
};
}(jQuery));
当我加载我的页面时出现此错误:
bootstrap-datepicker.de.js:7 Uncaught TypeError: Cannot set property 'de' of undefined
at bootstrap-datepicker.de.js:7
at bootstrap-datepicker.de.js:19
我们遇到了同样的问题,并通过将这段代码移到视图模型的构造函数中解决了这个问题
$(document).ready(() => {
(function($){
(<any>$.fn.datepicker).dates['de'] = {
days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
daysShort: ["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"],
daysMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
monthsShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
today: "Heute",
monthsTitle: "Monate",
clear: "Löschen",
weekStart: 1,
format: "dd.mm.yyyy"
};
}($));
$('#date').datepicker({
format: 'dd.mm.yyyy',
autoclose: true,
language: "de",
orientation: 'left bottom'
});
});
我正在将我们的项目切换到模块。所以大多数事情都在工作,但有些组件有一些问题。主要问题似乎是本地化文件。 如果我有这个例子的解决方案,我可以解决我项目中的其他问题。
我正在使用 Bootstrap 来自此处的日期选择器 https://bootstrap-datepicker.readthedocs.org/
Requirejs 配置:
require.config({
baseUrl: "Scripts",
paths: {
... some more like jquery and jquery-ui...
"bootstrap-datepicker": "bootstrap-datepicker",
"bootstrap-datepicker-de": "./locales/bootstrap-datepicker.de",
}
shim: {
'bootstrap-datepicker-de': ['bootstrap-datepicker']
}
});
App.ts:
... some more imports like jquery and jquery-ui...
import "bootstrap-datepicker";
import "bootstrap-datepicker-de";
... init App ...
bootstrap-datepicker.de.js
; (function ($) {
$.fn.datepicker.dates['de'] = {
days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
daysShort: ["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"],
daysMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
monthsShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
today: "Heute",
monthsTitle: "Monate",
clear: "Löschen",
weekStart: 1,
format: "dd.mm.yyyy"
};
}(jQuery));
当我加载我的页面时出现此错误:
bootstrap-datepicker.de.js:7 Uncaught TypeError: Cannot set property 'de' of undefined
at bootstrap-datepicker.de.js:7
at bootstrap-datepicker.de.js:19
我们遇到了同样的问题,并通过将这段代码移到视图模型的构造函数中解决了这个问题
$(document).ready(() => {
(function($){
(<any>$.fn.datepicker).dates['de'] = {
days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
daysShort: ["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"],
daysMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
monthsShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
today: "Heute",
monthsTitle: "Monate",
clear: "Löschen",
weekStart: 1,
format: "dd.mm.yyyy"
};
}($));
$('#date').datepicker({
format: 'dd.mm.yyyy',
autoclose: true,
language: "de",
orientation: 'left bottom'
});
});