我有 js 变量名称“reservationUrl”,我想在 handlebars 脚本中使用这个变量。
<script id="reservation-template" type="text/x-handlebars-template">
{{#each this}}
<a href="'+reservationUrl+'" class="viewReservationLink" >View
</a>
{{/each}}
</script>
有什么帮助吗?
最佳答案
只需将它用在 Handlebars 支架上就可以了
<script id="reservation-template" type="text/x-handlebars-template">
{{#each this}}
<a href="{{reservationUrl}}" class="viewReservationLink" >View</a>
{{/each}}
</script>
如果你想用任意变量替换模板本身的内容,你应该在渲染时将它传递给模板。这就是模板引擎的用途,用变量渲染模板,对吧? :)
关于javascript - Handlebars 脚本中的 JS 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47584355/