I'm trying to update a calendar by using the component Datepicker with Vue.js, but I have some problems regarding the adding and deleting of items (in this case, Date objects)
I have already developed two javascript functions: one used for adding new Dates to an array, and another one for deleting specific dates in the same array. The thing is, when the website is loaded, I can perfectly add new dates and delete the dates that initially were created. But what I can't do is to add a new date and then delete it, because with the function I developed, the method used to return the index of the date in the array returns -1.
addDate: function(event) {
var fecha = document.getElementById("inputFecha").value;
var fecha2 = new Date(fecha);
availableDates.push(fecha2);
},
deleteDate: function(event) {
var collection = availableDates,
d = new Date(event.getFullYear(), event.getMonth(), event.getDate()),
idx;
idx = collection.map(Number).indexOf(+d);
if(idx!=-1){
availableDates.splice(idx,1);
}
}
And some of the dates I initially created in the same file:
var availableDates = [];
availableDates.push(new Date(2019, 2, 29));
availableDates.push(new Date(2019, 2, 30));
availableDates.push(new Date(2019, 2, 28));
What I need is the possibility to add and delete without having to recharge the website.
fecha
– Jaromanda XavailableDates.push(new Date(fecha2.getFullYear(), fecha2.getMonth(), fecha2.getDate()))
– Stefan Blamberg