I'm trying to iterate over a json array of 3 objects in Jade in order to populate some html (3 is arbitrary, I have one user with 380+).
Instead of 3 divs, I'm getting about 5,000+. How do I iterate over this object from my Node.js sever so it will render properly in Jade/Pug? My guess is that, instead of giving me the length of the array (3), it's giving me the length of the json string that makes that array which is over 5,000.
My server is sending this:
res.render('yourUploads', {fromServer:JSON.stringify(rows[0])});
rows[0]
is the results from a mysql database query, 3 results.
script.
var data = !{fromServer};
console.log(data); //prints "(3) [Object, Object, Object]"
console.log(data.length); //prints "3"
mixin posMixin(uploadData)
div #{uploadData}
body
div Welcome to your awesome uploads page
div(onclick="window.location='/createNewUpload'") go to your awesome Create New Upload page
- for (i = 0; i < fromServer.length; ++i) { //fromServer.length is about 5,000?
+posMixin("whateverItTakesToGetThisToWork") //puts 5,000 divs into the dom!!!
- }
As you might have guessed, I'm not exactly sure of what to put in place of "whateverItTakesToGetThisToWork"
, but I wouldn't be surprised if it became rather obvious after I figure out what's wrong with this fromServer
object. I had thought it would be fromSever[i]
but that produces output so large it crashes my machine.
via Glen Pierce
No comments:
Post a Comment