新しいサイトのテンプレートに JSON と MUSTACHE を使用しています。しかし、json データから HTML を取得する方法がわかりません。APIプロバイダーとして機能するバックエンドでPHPを使用しています。私はこの概念に非常に慣れていません。すべてのヘルプと提案は大歓迎です。
ありがとう。
私が使用しているコード::
<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>
必要な出力:
ありがとうございます