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

212
Views
¿Cómo puedo ejecutar una función de bucle for y luego llamar a otra función después de que la función de bucle for se complete con un botón?

Estoy tratando de ejecutar una función después de analizar algunos CSV con Papaparse al hacer clic en el botón. Solo puedo hacerlo funcionar con dos botones, lo cual no es lo mejor. De hecho, tengo más código que actualizará la matriz selected_csv con el método push().

Lo que quiero hacer es enviar la matriz csv seleccionada a Papaparse for-loop y enviar () los resultados a la matriz_combinada, que luego usa la función gentil para agregar una tabla de imágenes. Probé asíncrono y esperé pensando que sería tan simple como agregar asíncrono y esperar en ambas funciones. Pero eso no funcionó en absoluto.

Cualquier ayuda sería muy apreciada. He llegado hasta aquí leyendo muchas preguntas de stackoverflow y modificando. Pero parece que no puedo hacer que el último bit funcione.

 var combined_arrays = []; function update() { var selected_csv = ['https://raw.githubusercontent.com/letsnotmakejunk/flashcards/main/Adjectives%201%20(State)%20(with%20subtitles).csv', 'https://raw.githubusercontent.com/letsnotmakejunk/flashcards/main/Adjectives%202%20(Condition)%20(with%20subtitles).csv']; //parse each entry of array and gen cards for (let l = 0, n = selected_csv.length; l < n; l++) { Papa.parse(selected_csv[l], { download: true, delimiter: ",", skipEmptyLines: true, header: true, complete: function(result) { //let selected_data = result.data; combined_arrays.push(...result.data); } }); }; }; function gentable() { var comb = combined_arrays; var columns = 6, table = document.createElement('table'), tbody = table.appendChild(document.createElement('tbody')), tr, td, img; let display = document.getElementById("cards"); for (i = 0, l = comb.length; i < l; i++) { if (i % columns == 0) tr = tbody.appendChild(document.createElement('tr')); let card = document.createElement("div"); card.setAttribute('class', 'card'); let qimages = document.createElement('img'); qimages.setAttribute('class', 'qimages'); qimages.setAttribute('src', '../.assets/' + comb[i].value); tr.appendChild(document.createElement('td')) .appendChild(card) .appendChild(qimages) //.src = '../.assets/' + combined_arrays[i].value; } display.appendChild(table).setAttribute('class', 'card_table'); };
 <script src="https://unpkg.com/papaparse@5.3.2/papaparse.min.js"></script> <div id='cards'> </div> <button onclick='update()'> testing </button> <button onclick='gentable()'> gentable </button>

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

0

Espero que esto sea útil, ¿quieres lograr esto? Para que la actualización de la función llame a gentilable. ¡Hágamelo saber!

 var combined_arrays = []; function update() { var selected_csv = ['https://raw.githubusercontent.com/letsnotmakejunk/flashcards/main/Adjectives%201%20(State)%20(with%20subtitles).csv', 'https://raw.githubusercontent.com/letsnotmakejunk/flashcards/main/Adjectives%202%20(Condition)%20(with%20subtitles).csv']; //parse each entry of array and gen cards for (let l = 0, n = selected_csv.length; l < n; l++) { Papa.parse(selected_csv[l], { download: true, delimiter: ",", skipEmptyLines: true, header: true, complete: function(result) { //let selected_data = result.data; combined_arrays.push(...result.data); if (l + 1 === selected_csv.length) { gentable(); } } }); }; }; function gentable() { var comb = combined_arrays; var columns = 6, table = document.createElement('table'), tbody = table.appendChild(document.createElement('tbody')), tr, td, img; let display = document.getElementById("cards"); for (i = 0, l = comb.length; i < l; i++) { if (i % columns == 0) tr = tbody.appendChild(document.createElement('tr')); let card = document.createElement("div"); card.setAttribute('class', 'card'); let qimages = document.createElement('img'); qimages.setAttribute('class', 'qimages'); qimages.setAttribute('src', '../.assets/' + comb[i].value); tr.appendChild(document.createElement('td')) .appendChild(card) .appendChild(qimages) //.src = '../.assets/' + combined_arrays[i].value; } display.appendChild(table).setAttribute('class', 'card_table'); };
 <script src="https://unpkg.com/papaparse@5.3.2/papaparse.min.js"></script> <div id='cards'> </div> <button onclick='update()'> 2 in 1 </button>

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!