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

77
Views
¿Cómo agregar un me gusta a algo pero solo una vez usando el almacenamiento local?

Estoy trabajando con una API y necesito mostrar películas y que me gusten, pero necesito que me gusten una vez. Intenté agregar un valor booleano y obtuve algo como esto:

 let beenLiked = false; const movieLike = document.getElementById("likeButton") movieLike.addEventListener('click', () => { console.log("ok like") axios.patch(`myUrl`) beenLiked = true }, true)

el problema es cuando me gusta una pelicula, no me puede gustar otra debido a mi booleano, como puedo modificarlo para resolver mi problema?

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

0

Si puede obtener el nombre de la película que se supone que le gustará (no tengo su archivo html para hacerlo por usted), puede rastrear los nombres y hacerlo así:

 let beenLiked = [] const movieLike = document.getElementById("likeButton") movieLike.addEventListener('click', () => { const movie = "The Movie" // Get the movie name or id which has to be liked if(beenLiked.indexOf(movie) === -1){ console.log("ok like") axios.patch(`myUrl`) beenLiked.push(movie) return true } console.log("Already liked once") return false })

aquí la versión simplificada sin html:

 let beenLiked = [] function a() { const movie = "The Movie" // Get the movie the likeButton is attached to if (beenLiked.indexOf(movie) === -1) { beenLiked.push(movie) return true } return false } console.log(a()) console.log(a())

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!