javascript 如何在Flowbite Datepicker中更改区域设置?

yr9zkbsy  于 2023-06-28  发布在  Java
关注(0)|答案(2)|浏览(158)

不幸的是,Flowbite Datepicker文档没有说明如何使用另一个语言环境,而是support is there
这是我如何实现日期选择器(工作):

import Datepicker from "flowbite-datepicker/Datepicker";

document.addEventListener("DOMContentLoaded", function () {
  document.querySelectorAll("[datepicker]").forEach(function (datepickerEl) {
    new Datepicker(datepickerEl);
  });
});

这就是我如何让本地化工作起来的:

import Datepicker from "flowbite-datepicker/Datepicker";
import { locales } from "../../node_modules/flowbite-datepicker/js/i18n/base-locales.js";
import de from "../../node_modules/flowbite-datepicker/js/i18n/locales/de.js";

locales.de = de;

const datepickerOptions = {
  language: "de",
  weekStart: 1,
};

document.addEventListener("DOMContentLoaded", function () {
  document.querySelectorAll("[datepicker]").forEach(function (datepickerEl) {
    const d = new Datepicker(datepickerEl);
    d.setOptions(datepickerOptions);
  });
});

但是我对模块化JavaScript的理解太差了,无法正确理解。This是引用原始代码的文件。对于有经验的人来说应该是直截了当的。

7gcisfzg

7gcisfzg1#

而不是locales.de = de,尝试Datepicker.locales.de = de
从源代码库中查看此参考。

6ljaweal

6ljaweal2#

我发现flowbite-datepicker是从vanillajs-datepicker派生出来的,在检查了他们的文档后,我得到了以下代码:

import Datepicker from "flowbite-datepicker/Datepicker";
import ja from "flowbite-datepicker/locales/ja";

const datepickerEl = document.getElementById("datepickerId");
Object.assign(Datepicker.locales, ja);
const datePicker = new Datepicker(datepickerEl, {
  language: 'ja',
});

相关问题