小胡子里面的小胡子 [英] Mustache inside of href

查看:80
本文介绍了小胡子里面的小胡子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的JSON:

 { "something": "http://something.com" }

和这样的HTML:

 <a href="{{something}}">{{something}}</a>

当我申请Mustache时,我得到

When I apply Mustache, I get

 <a href="%7B%7Bsomething%7D%7D">http://something.com</a>

但我想要的是

 <a href="http://something.com">http://something.com</a>

我已经尝试过 {{{something}}} {{& }} ,单引号,双引号......我甚至阅读文档。

I already tried {{{ something}}}, {{& something}}, single quotes, double quotes... I even read documentation.

你能帮助我吗?

推荐答案

确保您的模板源是直文 - 不要尝试将解析后的HTML源作为模板。浏览器会在你的链接href中urlencode / escape这些字符,并导致你看到的%7Bs %7Ds 你的代码。小胡子不会认识到这一点。

Make sure your template source is straight text - don't try and grab parsed HTML source as your template. Browsers will urlencode/escape those characters in your link href, and result in those %7Bs and %7Ds you see in your code. Mustache won't recognize that.

我认为你传递给小胡子的来源可能无效。

I suppose unescaping the source you pass to mustache might work, though.

Mustache.render(unescape(source),view)

这篇关于小胡子里面的小胡子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆