我在我的新网站中使用JSON和MUSTACHE模板。但我不知道如何从json数据中获取HTML。我在后端使用PHP,作为API提供者。我对这个概念很陌生。艾维的帮助和建议是受欢迎的。如何从JSON数据中获取HTML,使用MUSTACHE?
谢谢。
代码我使用::
<script>
// this is for base
this.get(/\#\/(.*)/, function(){
var send_url = '<?php echo $url?>sammy/' + this.params['splat'];
var context = this;
$.getJSON(send_url, function(data) {
var template = data.template;
context.renderEach('<?php echo $url?>mustache_templates/' + template + '', data.data).swap();
});
});
</script>
JSON数据就像是::
{"menu": {
"id": "file",
"string": "<a href=\"http:\/\/stackoverflow.com\/questions\/5335873\/how-to-get-html-from-json-data-using-mustache#xyz\">string</a>",
}}
胡子模板:
{{#string}}
<div>
{{string}}
</div>
{{/string}}
电流输出:
<a href="https://stackoverflow.com/questions/5335873/how-to-get-html-from-json-data-using-mustache#xyz">string</a>
输出需要:
感谢您
我很抱歉,我认为我无法解释它很好,实际上我没有将值传递给PHP,但从中获得价值..我编辑了问题以更好地理解..感谢您的回复。期待更多的帮助 – 2011-03-17 08:20:12