胡子里面有
Mustache inside of href
我有这样的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}}
,单引号,双引号... 我什至阅读了文档。
你可以帮我吗?
我认为您需要利用转义&
与模板脚本一起将模板包围起来:
<script type="text/template" id="tmpl">
<a href="{{& something }}">{{ something }}</a>
</script>
在这里找到这个例子。
确保模板源是纯文本 - 不要尝试获取解析的HTML源作为模板。浏览器将对您的链接 href 中的这些字符进行编码/转义,并产生您在代码中看到的那些%7Bs
和%7Ds
。小胡子不会认出这一点。
不过,我想摆脱你传递给小胡子的来源可能会起作用。
Mustache.render(unescape(source),view)
相关文章:
- 没有找到相关文章