1
我正在使用jQuery Mobile將AJAX發佈到服務器。 響應以JSON形式接收,我嘗試使用Mustache模板進行顯示。 一切正常,但jQuery無法正確呈現,例如它不會將類,樣式等添加到呈現的模板中。jQuery mobile,AJAX,Mustache無法正確呈現
加載模板和張貼:
$('#continueToHome').click(function() { // called on button click
// call ajax, send no params, receive json
$.post("http://localhost:3000/app_login.json", "", function(result){
// load template
var template = $('#personTpl').html();
// render data into template
var html = Mustache.to_html(template, result);
// append to page
$('#sampleArea').html(html);
});
// display page
$.mobile.changePage("#page-homepage", { transition: "slide"});
});`
的HTML:
<script id="personTpl" type="text/template">
<h1>{{first_name}} {{last_name}}</h1>
Email: {{email}} <br>
<h3>Smifrs</h3>
<ul data-role=listview>
{{#usmifrs}}<li><a href=#>{{name}}</a></li>
{{/usmifrs}}</ul>
</script>
<div id="sampleArea"></div>
問題是,它無法正確顯示。 當我有'data-role = listview'的常規'ul'元素時,jQuery爲'li'標籤注入class ='ui-listview',div和樣式,但是當我使用我的模板時,它不會發生。
我想我應該以某種方式重新加載頁面,但我找不到如何。
感謝您的幫助。
你能告訴我什麼是這個URL'HTTP返回://本地主機:3000/app_login.json'也,你可以更新JSON要傳遞到小鬍子模板qustions – rizwaniqbal