![](/img/trans.png)
[英]Returning Nested Object of JSON Data to Mustache Template Using jQuery getJSON
[英]Mustache JS using $.getJSON
嗨,我正在使用Mustache JS使用JSON獲取數據。 我的模板在下面。
<script id="patientTabl" type="text/template">
<table class="bordered">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Patient Id</th>
<th>SSN</th>
</tr>
</thead>
<tbody>
{{#patients}}
<tr>
<td data-title="First Name">{{firstName}}<div href="#" class="tool-tip">
<span class="right-arrow">
<img class="callout" src="images/callout.gif" />
<ul>
<li><a href="update-patient.html?id={{id}}">View/Update Patient</a></li>
<li><a href="JavaScript:getInsurPlans()" id="viewInsurPlans">View Insurance Plans</a></li>
<li><a href="patient-admission.html?id={{id}}">Create Patient Admission</a></li>
</ul>
</span>
</td>
<td data-title="Last Name">{{lastName}}</td>
<td data-title="Phone Number"> {{phones}}</td>
<td data-title="Patient Id">{{id}}</td>
<td data-title="SSN">{{ssn}}</td>
</tr>
{{/patients}}
</tbody>
</table>
</script>
為此,我正在編寫下面的jQuery代碼以將數據提取到模板中。 我得到響應,但數據未插入模板。 請幫忙
$.getJSON('/ePhase-web/patients', function (data) {
var template = $('#patientTabl').html();
var html = Mustache.to_html(template, data);
$('#sampleArea').html(html);
});
很難說到底出了什么問題。 我沒有看到任何明顯的錯誤。 因此,進行常規調試是有必要的。
大多數瀏覽器都有某種網絡標簽。 它顯示正在發出的請求嗎? 請求成功了嗎? 僅在請求成功時才調用您的方法。
如果請求成功,您可以調試代碼本身。 在開發控制台打開的情況下,您可以將調試器一詞放在要暫停的位置,以便檢查變量的值(通過將鼠標懸停在變量上)
結果,病人選擇的jquery選擇是否給出正確的元素?
“數據”是什么樣的? 調用mustache.to_html時會引發錯誤嗎? HTML是什么樣的?
$(“#sampleArea”)是否找到任何元素?
我認為,一個個地解決這些問題將使您更正錯誤或提出更可解決的答案。 另請參閱有關chrome調試的本文
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.