英文:
How to apply method to AirDatepicker in my custom js file?
问题
我在app.js文件中定义了一个AirDatepicker v3.3.5,如下:
window.dateRangePicker = new AirDatepicker('.date-range', {
range: true,
maxDate: new Date(),
multipleDatesSeparator: ' - '
});
在https://air-datepicker.com/examples文档中查看,
我需要在我的custom form.js中添加onSelect和update方法,如下:
dpMin = new AirDatepicker('#el1', {
onSelect({date}) {
dpMax.update({
minDate: date
})
}
})
但是我失败了,因为我尝试了以下代码:
window.dateRangePicker.onSelect({date}) {
...
};
但是我收到了错误消息:
期望新行或分号
哪种语法是有效的?
英文:
I have a AirDatepicker v3.3.5 defined in app.js file as :
window.dateRangePicker = new AirDatepicker('.date-range', {
range: true,
maxDate: new Date(),
multipleDatesSeparator: ' - '
});
Looking at https://air-datepicker.com/examples docs
I need in my custom form.js to add to apply onSelect and update methods like
dpMin = new AirDatepicker('#el1', {
onSelect({date}) {
dpMax.update({
minDate: date
})
}
})
But I failed it, as I tried :
window.dateRangePicker.onSelect({date}) {
...
};
But I got error :
Expecting new line or semicolon
Which syntax is valid ?
答案1
得分: 1
根据评论中提到的内容,文档表示我们可以在初始化时将onSelect
方法传递给选项,但在创建的对象本身上并没有onSelect
方法。
当我检查并跟踪分配的对象时,我发现我们可以利用作为创建对象的一部分公开的函数。我们可以在初始化后分配该方法,如下所示。
您可以尝试类似以下的内容。
window.dateRangePicker.opts.onSelect = ({ date }) => {
console.log(date);
}
英文:
As mentioned in the comments, Document says we can pass the onSelect
method inside the options at the time of initialisation but they don't have onSelect method on that created object itself.
When i checked and traced the assigned object i find that we can utilise the functions exposed as part of created object. We can assign the method after initialisation like below.
You can try something like this.
window.dateRangePicker.opts.onSelect = ({date}) => {
console.log(date);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论