mustache.jsを使って、
mustaches.js テンプレートを読み込むために、ブラウザの標準ページ ローダーに依存したいと考えています。
つまり、JQuery リクエスト ($.get) を削除してテンプレートをメモリに取り込み、テンプレートを別の html ファイルに残したいということです。今のところこの作品:
ファイル contact.html:
<script id="tpl-test" type="text/html">
<h1> {{firstname}} </h1>
</script>
ファイル my.js
$.get("tpl/contact.html", function(templates){
var template = $(templates).filter('#tpl-test').html();
var jdata={firstname: 'fname'};
$('body').append(Mustache.render(template, jdata));
});
そして、私はこれに似たものが欲しいです:
contact.html ファイル (そのまま)
jquery $.get リクエストの代わりに、次のことをお勧めします。
index.html で:
<script id="tpl-test" src="tmpl/contact.html" type="text/html"></script>
更新: Chrome では、テンプレートは次のように読み込まれます。
ファイル my.js (私の願いですが、これは機能しません)
function ondemand(){
var template = $(templates).filter('#tpl-test').html();
var jdata={firstname: 'fname'};
$('body').append(Mustache.render(template, jdata));
});
前もって感謝します。