passing array of image objects to the jade and then displaying via jade

时间秒杀一切 提交于 2019-12-12 03:45:54

问题


Here, I have use.js and use.jade.

In use.js, I am simply mapping hardcoded image variable img_01 from jade to use.js by specifying var $image= $(pclass + 'img_01');

In .js, I am assigning $image by some useful image using $image.attr('src', useful_image) Using img.use--img_01 in .jade, I am able to display the image (useful_image). Now, my constraint is I don't want to hard code in .jade and let .jade display images as many as provided by .js.

So, I am able to create the array in .js of var $image=[] and then $image.push($(pclass + 'img_' + N.toString()) where N varies from 0 to K (lets say K =3).

Now I want to call these img_0, img_1, img_2 .....img_K in .jade and display them on page.

So my specific question is I am not able to iterate [img_0, img_1, img_2 .....img_K] in .jade. Can anyone tell what could be best method to do so????

Pls note: I used rendering method. For the same I used

var express = require('express'); var app = express();

But, node.js gets crashed with this itself leave aside using app.get...


回答1:


You can pass object from server to client in this way.

 app.get(..., function (req, res) {
        var stats = { ... };
        res.render('chart', { images: $arrImage });
     });

For looping at client ,you can use jade#each.

each oneImage in images
 img( src=oneImage.image)

Note : Jade is depricated,So try to use Pug#each



来源:https://stackoverflow.com/questions/42777077/passing-array-of-image-objects-to-the-jade-and-then-displaying-via-jade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!