我在我的新站点中使用 JSON 和 MUSTACHE 作为模板。但我不知道如何从 json 数据中获取 HTML。我在后端使用 PHP,它作为 API 提供者工作。我对这个概念很陌生。欢迎大家提供帮助和建议。
谢谢。
我正在使用的代码::
<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>
需要的输出:
谢谢