سؤال

I have an app that currently is all client-side.

What it does is when you upload an XML file, it generates new elements and puts them on the page using jQuery.

How many and what is inside those elements depends on what is in the file that is uploaded. The format that the generated elements are in is basic HTML.

I am in the process of moving that to the server-side right now using express.js and node.js and I can't figure out how to do what I have going on the client-side.

Especially considering that you use Jade for the templates in the server-side.

Right now I have this to handle the page:

res.render('preview', {##jade elements placed here##});

I'm curious, can I use like a for loop in the second argument of res.render to make new elements?

If not, how can I do what I want? (and by what I want, I mean dynamically add elements to a page)

هل كانت مفيدة؟

المحلول

You cannot pass a for a loop code as second parameter to the res.render call. The parameter should be a valid JSON. But you can always do

var obj = {};

// Here you can loop to manipulate and add data to obj
// or even
obj.key1 = "val1";
obj.array1 = [1,2,3];
obj.obj1 = {key:1};

res.render('preview', obj);

and in preview.jade template you can loop over and display the elements of obj

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top