1
Mustache.jsでrender
ajax応答にしたいのですが、何らかの理由でテンプレート内の変数が表示されません。私はMustacheのデリミタを変更しましたが、それでも動作していません。Djangoテンプレート内のMustache.jsは機能しません
の.js
/*
* Get reservation preview snippet.
*/
$(document).ready(function() {
Mustache.tags = ['<%', '%>'];
var tableRows = $("#table-wrapper table tr");
// table row was clicked
tableRows.click(function(e) {
e.preventDefault();
var $this = $(this);
var previewURL = $(this).find("#ajax_id").attr('data-id');
// get preview and load it to template
$.getJSON(previewURL, function(reservation) {
console.log("Updated at: " + reservation.updated_at);
var template = $('#reservationPreviewTpl').html();
var html = Mustache.render(template, reservation);
console.log('HTML' + html);
$('#test123').html(html);
});
});
テンプレート
<div id="test123"></div>
<script id="reservationPreviewTpl" type="text/template">
<h1>I am a template</h1>
<p><% reservation.updated_at %></p>
</script>
コンソール出力
@andlrcする必要がありますアウト
reservation.updated_at
ターン:私は質問を更新しました、 'reservation.updated_at'はかかわらず、動作しているようです – intelis