我正在尝试进行 2 个输入 - 一个带有 pickadate ,另一个带有 pickatime。当用户选择一个日期时,禁用时间数组被传递给 pickatime 函数。我有两个使用 php 从后端传递的数组。我正在服用这些并使用需要禁用的时间/日期。我的代码:
$('#myfield1').pickadate({
format: 'yyyy-mm-dd',
//array with dates
disable: exclude_days_real,
//I want to render new pickatime every time I choose a new date
onSet: function() {
//check if there are disabled hours in a date user have chosen
var chosen_date = $('#myfield1').val();
var disabled_time_real = [];
//if there are disabled hours, make them correct array from js object
if (time_array[chosen_date]) {
var disabled_time = time_array[chosen_date];
for (i = 0; i < disabled_time.length; i++) {
var time = disabled_time[i];
var time_synt = time.split(':');
disabled_time_real.push(time_synt);
}
}
//make time input field blank
$('#myfield2').val('');
//and here I think it should render time select every time date is set, but it works only one time
$('#myfield2').pickatime({
format: 'H:i',
interval: 60,
min: [10, 00],
max: [16, 00],
disable: disabled_time_real
});
}
});
每次用户选择新日期时,我怎样才能让它呈现?我考虑过删除输入并插入新的,但我认为它应该有更好的解决方案。