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

209
Views
¿Cómo crear y agregar nuevos divs dentro de un bucle?

Estoy trabajando en una aplicación similar a Twitter para la clase. Estoy tratando de crear un nuevo $tweet para cada iteración de bucle y agregar cada &tweet en mi contenedor de $feed. Sin embargo, cuando se ejecuta, solo se muestra el primer tweet de la matriz. Mi hipótesis es que solo se crea y agrega un $tweet y que cada iteración simplemente lo sobrescribe. Aquí está mi código de muestra.

 var renderfeed = function() { $feed.empty(); var index = streams.home.length - 1; while (index >= 0) { // for (var i = 0; i < index + 1; i++) { var tweet = streams.home[index]; var $tweet = $('<div class="tweet"></div>'); $tweet.appendTo($feed); console.log(tweet); console.log(streams.home); console.log($tweet); //assingning values to variable to be pushed into $tweet div, icons already established $userName.text('@' + tweet.user); $profilePhoto.attr("src", tweet.profilePhotoURL); $message.text(tweet.message); $timeStamp.text(tweet.created_at); //appending child elements to $tweet $profilePhoto.appendTo($tweet); $userName.appendTo($tweet); $message.appendTo($tweet); $timeStamp.appendTo($tweet); $like.appendTo($tweet); $retweet.appendTo($tweet); $comment.appendTo($tweet); $share.appendTo($tweet); index -= 1; } };
  • Streams.home es una matriz de objetos
about 4 years ago · Juan Pablo Isaza
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!