简体   繁体   English

如何将把手模板插入外部Javascript文件?

[英]How to insert handlebars template to external Javascript file?

I want to separate the javascript file in a handlebars file,but unfortunately it wont work. 我想将JavaScript文件分隔为车把文件,但不幸的是它将无法正常工作。

Attempt : 尝试:

index.handlebars : index.handlebars:

<script src = "javascript/detail.js"></script>

detail.js detail.js

{ { #each restaurants } }
var marker = L.marker([{{ this.restaurant.location.latitude }}, { { this.restaurant.location.longitude } }]).addTo(mymap);
{{/each}}

I always get this error : Uncaught SyntaxError: Unexpected token 我总是收到此错误:Uncaught SyntaxError:意外的令牌

When I put the code inside detail.js to the bottom of index.handlebars,it works. 当我将detail.js内的代码放在index.handlebars的底部时,它可以工作。

I think I found the solution. 我想我找到了解决方案。 Basically I just copy paste the script into a partial handlebars file, and then just write the partial tag 基本上,我只是将脚本复制粘贴到部分把手文件中,然后编写部分标签

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

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