简体   繁体   English

tempusdominus 4多选择人群

[英]tempusdominus 4 multiselect population

I'm trying to get initialized my DateTimepicker with multiple Dates. 我正在尝试使用多个日期初始化DateTimepicker。 I can initalized with a specific date but not with the multiple option. 我可以指定一个特定日期,但不能使用多个选项。

var selectedDates = ["12/1/2019","11/1/2019"];
    $(function () {
                $('#holidayPicker').datetimepicker({
                    format: 'L',
                    allowMultidate: true,
                    multidateSeparator: ' ',
                    minDate: "<?php echo $startDate->format('Y-m-d');?>",
                    maxDate: "<?php echo $endDate->format('Y-m-d');?>",
                   //   setDate: [new Date(2019, 0, 4),new Date(2019, 0, 5)]
                    useCurrent: false,
                    //date: new Date(2019, 0, 4),
                    setDate: selectedDates,
                });
            });

What i have already tried: 我已经尝试过的

  • with setDate an a array of Dates and Strings 与setDate的日期和字符串数组
  • with date and multiple Strings or multiple Dates as Strings 日期和多个字符串或多个日期作为字符串
  • directly over the value attribut of the input field 直接在输入字段的值属性上方

Does someone has an idea? 有人有主意吗?

I have managed to find a function in the source code that allows you to set the date directly. 我设法在源代码中找到一个函数,该函数可让您直接设置日期。 You have to access the datetimepicker object directly in order to use it. 您必须直接访问datetimepicker对象才能使用它。

Code snippet: 程式码片段:

var $el = ('#your-element');
// Initialize datepicker.
$el.datetimepicker({
    inline: true,
    format: 'DD-MM-YYYY',
    allowMultidate: true,
    useCurrent: false // Prevents selection of current date
});

// Get the object directly from the data attribute.
// @see https://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/
var prefill = ['01-15-2019', '01-16-2019'];
var plugin = $el.data('datetimepicker');
for(let i = 0; i < prefill.length; i++) {
    // Set the dates as active. You can optionally pass your own moment object as the first argument.
    plugin.date(prefill[i], i);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM