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

219
Views
¿Cómo puedo alternar la clase de fila después de los datos de API?

He intentado todo lo que sé y no puedo hacer que funcione una clase de tablerow alterada, sin tener todas las filas duplicadas o sin tener un montón de filas ficticias insertadas

Esto es lo que tengo

 <script> fetch("https://www63.myfantasyleague.com/2021/export?TYPE=league&L=43570&JSON=1").then( res => { res.json().then( data => { console.log(data.league.franchises.franchise); if (data.league.franchises.franchise.length > 0) { var temp = ""; temp += "<table id='league_emails'>"; temp += "<tbody>"; temp += "<tr><th>Franchise</th><th>Owner Name</th><th>Email</th></tr>"; data.league.franchises.franchise.forEach((itemData) => { for (var i = 0; i < data.league.franchises.franchise.length; i++) { if (i % 2) temp += '<tr class="eventablerow">'; else temp += '<tr class="oddtablerow">'; } temp += "<td>" + itemData.name + "</td>"; temp += "<td>" + itemData.owner_name + "</td>"; temp += "<td>" + itemData.email + "</td>"; }); temp += "</tbody>"; temp += "</table>"; document.getElementsByClassName('commish_league_safe')[0].innerHTML = temp; } } ) } ) </script> <div class="commish_league_safe"></div>

El problema radica aquí y probé una docena de cosas y lo envolví de diferentes maneras

 for (var i = 0; i < data.league.franchises.franchise.length; i++) { if (i % 2) temp += '<tr class="eventablerow">'; else temp += '<tr class="oddtablerow">'; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 <script> fetch(https://www63.myfantasyleague.com/2021/export?TYPE=league&L=43570&JSON=1).then( res => { res.json().then( data => { console.log(data.league.franchises.franchise); if (data.league.franchises.franchise.length > 0) { var temp = ""; temp += "<table id='league_emails'>"; temp += "<tbody>"; temp += "<tr><th>Franchise</th><th>Owner Name</th><th>Email</th></tr>"; data.league.franchises.franchise.forEach((itemData,i) => { /* for (var i = 0; i < data.league.franchises.franchise.length; i++) { */ if (i % 2) temp += '<tr class="eventablerow">'; else temp += '<tr class="oddtablerow">'; /* } */ temp += "<td>" + itemData.name + "</td>"; temp += "<td>" + itemData.owner_name + "</td>"; temp += "<td>" + itemData.email + "</td>"; temp += "</tr>"; }); temp += "</tbody>"; temp += "</table>"; document.getElementsByClassName('commish_league_safe')[0].innerHTML = temp; } } ) } ) </script> <div class="commish_league_safe"></div>

Justo antes de terminar el ciclo, cierre la etiqueta tr. temp += "" + itemData.email + ""; después de esta línea, simplemente agregue la etiqueta de cierre para agregarla a la variable temporal.

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!