我有这样的JSON:
{ "something": "http://something.com" }
和这样的HTML:
<a href="{{something}}">{{something}}</a>
当我申请胡子时,我得到了
<a href="%7B%7Bsomething%7D%7D">http://something.com</a>
但我想要的是
<a href="http://something.com">http://something.com</a>
我已经尝试了{{{ something}}}
,{{& something}}
,单引号,双引号......我甚至阅读了文档。
你能帮助我吗?
答案 0 :(得分:11)
我认为您需要使用&
进行转义,并使用模板脚本包围您的模板:
<script type="text/template" id="tmpl">
<a href="{{& something }}">{{ something }}</a>
</script>
找到此示例over here。
答案 1 :(得分:4)
确保您的模板源是纯文本 - 不要尝试将解析后的HTML源作为模板。浏览器会在您的链接href中对这些字符进行urlencode / escape,并生成您在代码中看到的%7Bs
和%7Ds
。胡子不会认识到这一点。
我认为你传递给小胡子的来源可能无效。
Mustache.render(unescape(source),view)