从脚本标签访问车把属性

The*_*dor 2 javascript express handlebars.js

在车把模板中,我可以访问脚本标签内的车把参数,如

<script>     
  var aList = {{list}}
</script>
Run Code Online (Sandbox Code Playgroud)

模板是从expresswith调用的

 response.render('template', {list: [1, 2, 3]})
Run Code Online (Sandbox Code Playgroud)

小智 5

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

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

   <script>
   var aList = document.getElementById("thingIWant").value;
   </script>
Run Code Online (Sandbox Code Playgroud)