Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
Pasar el valor de la variable desde el selector de fecha

Tengo un selector de fecha en el que creo una variable y determino qué día de la semana seleccionamos

 let dayofweek1 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; let dayOfWeek = dayofweek1[e.date.getDay()]; console.log(dayOfWeek)

Función completa:

 $('#reservation-date').datepicker({startDate: '+0d'}).on('changeDate', function (e) { const arDate = e.date.toString().split(' '); let input = $('[name="RestaurantReservationForm[date]"]'); let dayofweek1 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; let dayOfWeek = dayofweek1[e.date.getDay()]; console.log(dayOfWeek) input.val(arDate[3] + '-' + (e.date.getMonth() + 1) + '-' + arDate[2]); _self.unSetError(input); $('#reservation-date .js-value').text(arDate[2] + ' ' + arDate[1]); });

Y quiero usar esta variable dayOfWeek en otra función

 filterTimes: function () { if ((["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"].indexOf(dayOfWeek) >= 0)) { let workHours = getWorkHoursForDay(json, restaurantID, dayOfWeek); let items = document.querySelectorAll(".dropdown-menu.dropdown-menu-height-fixed li a"); for (let item of items) { let itemValue = parseFloat(item.getAttribute('data-value')); item.parentNode.classList[((itemValue < parseFloat(workHours.open)) || (itemValue > parseFloat(workHours.close)) ? "add" : "remove")]("invisible"); } } }

¿Cómo puedo declarar esta variable con el valor del día seleccionado globalmente?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. Intente declarar la variable fuera de la función.
  2. He leído que las variables que no se declaran tienen un alcance global, pero esta no es una buena práctica.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!