简体   繁体   English

HTML 和脚本部分中的引导变量

[英]Bootstrap variable in the HTML and script part

I am sending data read from a database with res.render('default/index', {posts: posts});我正在发送从数据库读取的数据res.render('default/index', {posts: posts}); to a handlebars template.到车把模板。

This code will display images correctly:此代码将正确显示图像:

{{#each posts}}
    <div class="col">
        <img src="data:image/png;base64,{{imagefile}}">
     </div>
{{/each}}

Now I want to display the images in a carousel.现在我想在轮播中显示图像。 For this I need a script in addition to the html part.为此,除了 html 部分之外,我还需要一个脚本。

How do I use the posts values in the script?如何在脚本中使用帖子值?

<script>
.......
$('<div class="item"><img src="????????????"><div class="carousel-caption"></div>   </div>').appendTo('.carousel-inner');
......
</script>

Thank you in advance for a hint.提前感谢您的提示。

Thank you Emiel very much for your help.非常感谢 Emiel 的帮助。 Now I output the images in handlebars.现在我 output 车把中的图像。 Within the script, only the indicators are created and the active attributes are assigned.在脚本中,仅创建指标并分配活动属性。 The variable "posts" is only used to determine the number of images for a counter.变量“posts”仅用于确定计数器的图像数量。 Not very elegant, but it works:不是很优雅,但它有效:

var j=0;

{{#each posts}} 
j++ 
{{/each}}

j is equal to the number of pictures. j 等于图片的数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM