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
No se puede obtener una matriz de objetos asignada para mostrar en la tabla HTML Reaccionar

No puedo entender qué podría estar mal. Estoy tratando de mapear datos que se ven así.

 [ RowDataPacket { id: 1, words: 'one', numbers: 1 }, RowDataPacket { id: 2, words: 'two', numbers: 2 } ]

en una tabla pero termina sin mostrar nada.

Lo he intentado incluso con forEach pero el mismo resultado, realmente si alguien me ayuda con este, realmente lo agradecería.

 function TableCrud ({dbIo, isLoading, dbData}){ async function triggerFetch() { const dbData = await dbIo('getData') console.log(dbData + ' dbData awaited inside TableCrud')// Console.log } function insertRow(data) { if (isLoading) { triggerFetch() return ( <tr> <td id='no-data' colSpan='3'>Wait...</td> </tr> ) } else if(data.length === 0) { return ( <tr> <td id='no-data' colSpan='3'>Nothing to Display</td> </tr> ) } else { data.map((item, index) => { return ( <tr key={index}> <td>{item.words}</td> <td>{item.numbers}</td> <td><input className='input-check' id={'select-'+index} type="checkbox"/></td> </tr> ) }) } } return ( <div id='table-data'> <table id='table'> <thead> <tr> <th>Word</th> <th>Number</th> <th>Selected</th> </tr> </thead> <tbody id='table-body'> {insertRow(dbData)} </tbody> </table> </div> ) }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

puedes intentar algo como esto

 if(!data){ return ( <tr> <td id='no-data' colSpan='3'>Nothing to Display</td> </tr> )else if(data.length !== 0){ data.map((item, index) => { return ( <tr key={index}> <td>{item.words}</td> <td>{item.numbers}</td> <td><input className='input-check' id={'select-'+index} type="checkbox"/></td> </tr> ) }) } }
about 4 years ago · Juan Pablo Isaza Report

0

Creo que su muestra no es JSON válida:

 [ RowDataPacket { id: 1, words: 'one', numbers: 1 }, RowDataPacket { id: 2, words: 'two', numbers: 2 } ]

Tendría que verse así para trabajar con su mapa:

 [ { id: 1, words: 'one', numbers: 1 }, { id: 2, words: 'two', numbers: 2 } ]
about 4 years ago · Juan Pablo Isaza Report

0

Sentencia de retorno perdida. Debería ser como:

 return data.map((item, index) => { return ( <tr key={index}> <td>{item.words}</td> <td>{item.numbers}</td> <td><input className='input-check' id={'select-'+index} type="checkbox"/></td> </tr> ) })

Entonces la función puede devolver el resultado de map(). :)

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!