2013-01-24 3 views
0

현재 Mustache.js 템플릿에 문제가 있습니다. 모든 것이 정확하고 템플릿이 페이지에 HTML로로드됩니다. 하지만 JSON 데이터에 액세스 할 수 없기 때문에 그 이유를 확실히 알 수 없습니다. 누구든지 도와 줄 수 있습니까? 미리 감사드립니다.JSON/Mustache.js에서 템플릿이 작동하지 않습니다.

아래에서 자바 스크립트를 사용하고 있습니다.

query.find({ 
     success: function(results){ 
     var template = $("#newCurrItem").html(); 


     var newContents = Mustache.to_html(template, results); 
     $("#curr-list").append(newContents); 
     }, 
     error: function(error){ 
      console.log("error"); 
     } 

    }); 

이 이미지는 JSON 형식을 보여줍니다

http://i.imgur.com/JrYrORk.png?1

을 그리고, 여기에 템플릿입니다 :

<script id="newCurrItem" type="text/html"> 
    {{#results}} 
    <!-- Template for new curriculum --> 
    <li id="curr-list-item"> 


      <div id="curr-item"> 
      <input type="checkbox" class="item-delete"> 
      <label id="item-content" class="item-content">{{curr}}</label> 

    </div> 
    </li> 
    {{/results}} 
</script> 
+0

수 있습니다 당신은 crea 바이올린? http://jsfiddle.net/ –

답변

0

것은 더이처럼 JSON 데이터를 구조화 해보십시오 :

{ "results" : [ 
     { 
      "curr": "curr_dbc", 
      "createdAt" : ..., 
      "updatedAt":... 
     } 
    ]};