2016-05-28 2 views
1

Mustache.jsrender 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> 

コンソール出力

enter image description here

+0

@andlrcする必要がありますアウトreservation.updated_atターン:私は質問を更新しました、 'reservation.updated_at'はかかわらず、動作しているようです – intelis

答えて

0

はちょうどupdated_at

テンプレート

<div id="test123"></div> 
<script id="reservationPreviewTpl" type="text/template"> 
<h1>I am a template</h1> 
<p><% updated_at %></p> 
</script> 
関連する問題