read arrays in jade

Asked

Viewed 63 times

1

I need to read an array on my jade page.

In my controller I am passing as follows:

res.render('graphics/index', {namesClient:JSON.stringify(namesClient)}  

In jade I’m reading as follows:

var names= !{JSON.stringify(namesClient)};  

However, I need to upload the information from namesClient[i].name, how do I read?

2 answers

1

Do not convert the array to string between Node and Jade. Pass directly

res.render('graphics/index', {namesClient:namesClient}

and Jade Ode you can use namesClient[i].name. Only if you want to switch to Javascript (client side) do you need to convert to string.

1

        - var names= JSON.parse(namesClient);
        - for (var i = 0; i < names.length; i++)
             label [j] #{names[i].name}
  • It doesn’t make much sense to convert to String on Node to "disconnect" in Jade. You can switch directly to Jade as I described in my reply.

  • I am using in other places, so that I could read it was necessary to go out like this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.