我在ts中有功能
export function minutesToHoursAndMinutes(m, zeroPadded) {
if (zeroPadded == null) { zeroPadded = false; }
let hours:any = Math.floor(m / 60);
if (zeroPadded && (`${hours}`.length === 1)) { hours = `0${hours}`; }
let minutes:any = m % 60;
if (zeroPadded && (`${minutes}`.length === 1)) { minutes = `0${minutes}`; }
if ((hours === 24) && (minutes === '00')) {
hours = 23;
minutes = 59;
}
return [hours, minutes];
};
并试着像这样使用它
if (("#t-time-range").length > 0) {
$("#t-time-range").slider({
range: "min",
value: filter_max.max_traveltime,
min: filter_max.min_traveltime,
max: filter_max.max_traveltime+15,
step: 15,
slide(event, ui) {
const hms = FilterFunctions.minutesToHoursAndMinutes(ui.value );
$("#t-time").val(`Max ${hms[0]}t ${hms[1]}m`);
return $('#filter_travel_time').val(ui.value);
}
});
const hms = FilterFunctions.minutesToHoursAndMinutes($("#t-time-range").slider("value"));
$("#t-time").val(`Max ${hms[0]}t ${hms[1]}m`);
$('#filter_travel_time').val($("#t-time-range").slider("value"));
}
但我对argues有错误
喜欢这个
预期2个参数,但得到1.
如何让2参数可选?
答案 0 :(得分:0)
尝试将滑块对象的最后一个属性更改为
slide: function(event, ui) {
const hms = FilterFunctions.minutesToHoursAndMinutes(ui.value );
$("#t-time").val(`Max ${hms[0]}t ${hms[1]}m`);
return $('#filter_travel_time').val(ui.value);
}
答案 1 :(得分:0)
也许设置一个默认值,例如
export function minutesToHoursAndMinutes(m, zeroPadded=null)
。
这种方式已经设置了值,如果你没有传递参数,它将默认为空值。
答案 2 :(得分:0)
?
使参数可选。 Reference。
export function minutesToHoursAndMinutes(m, zeroPadded?) {