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

248
Views
React Typescript: la matriz no se asigna a través de todos los elementos

Tengo la siguiente tabla / matriz: ingrese la descripción de la imagen aquí

Si presiono el botón azul, todos los artículos con el mismo grupo que el registro deberían cambiar el Estado (Gratis). Pero ahora solo cambia el valor del registro y todos los elementos que se encuentran arriba. Como ejemplo, si presiono el Botón en el Registro No. 1, entonces él mismo y todos los anteriores (No. 0) obtienen un cambio de Estado (Gratis).

Siguiendo el código que estoy usando para revisar la matriz y cambiar el Estado:

 private _updateFreeStatus = (record: QuestionModel): void => { fetch('api/Test/UpdateGratisStatus', { headers: { 'Content-Type': 'application/json' }, method: 'PUT', body: JSON.stringify({ 'group': record.group, 'free': record.free, }) }); this.state.question.map(item => { if (item.group === record.group) { item.free = !record.free; } }); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. no mutes el estado
  2. crea una copia y usa setState

Usar

 const updatedQuestions = this.state.question.map(item => { if (item.group === record.group) { return { ...item, free: !record.free } } return item; }); this.setState({question: updatedQuestions});
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!