从脚本标签访问车把属性 [英] Access handlebars properties from script tag

查看:48
本文介绍了从脚本标签访问车把属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在车把模板中,我可以访问脚本标记内的车把参数吗?

In a handlebars template, can I access a handlebar parameter inside a script tag like

<script>     
  var aList = {{list}}
</script>

使用

express调用模板

 response.render('template', {list: [1, 2, 3]})

推荐答案

您可以在html中使用包含所需值的隐藏输入,然后使用script标记中的document.getElementById进行获取.

You can use a hidden input in your html that contains the value you want and then get that using document.getElementById in the script tag.

   <input type = "hidden" id = "thingIWant" value = {{list}} />

   <script>
   var aList = document.getElementById("thingIWant").value;
   </script>

这篇关于从脚本标签访问车把属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆