问题描述
在这里,我有use.js和use.jade.
Here, I have use.js and use.jade.
在use.js中,我只是通过指定 var $ image = $(pclass +'img_01');
将玉器中的硬编码图像变量 img_01
映射到use.js.>
In use.js, I am simply mapping hardcoded image variable img_01
from jade to use.js by specifying var $image= $(pclass + 'img_01');
在.js中,我使用一些有用的图像分配$ image. $ image.attr('src',有用的图像)
使用.jade中的 img.use--img_01
,我可以显示图像(useful_image).现在,我的约束是我不想在.jade中进行硬编码,而让.jade显示尽可能多的.js图片.
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.
因此,我可以在 var $ image = []
的.js中创建数组,然后在 $ image.push($(pclass +'img_'+ N.toString())
,其中N从0到K不等(假设K = 3).
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).
现在,我要在.jade中调用这些 img_0,img_1,img_2 ..... img_K
并将其显示在页面上.
Now I want to call these img_0, img_1, img_2 .....img_K
in .jade and display them on page.
所以我的具体问题是我无法在.jade中迭代 [img_0,img_1,img_2 ..... img_K]
.谁能告诉我这样做的最好方法是什么??
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();
但是,node.js本身因使用app.get ...而崩溃……
But, node.js gets crashed with this itself leave aside using app.get...
推荐答案
您可以通过这种方式将对象从服务器传递到客户端.
You can pass object from server to client in this way.
app.get(..., function (req, res) {
var stats = { ... };
res.render('chart', { images: $arrImage });
});
要在客户端循环,可以使用 jade#each
.
For looping at client ,you can use jade#each
.
each oneImage in images
img( src=oneImage.image)
注意:翡翠已被贬低,因此请尝试使用 Pug#each
Note : Jade is depricated,So try to use Pug#each
这篇关于将图像对象数组传递给玉器,然后通过玉器进行显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!