我正在尝试学习Mustache框架,并将其与jQuery Mobile和Ajax结合使用。
第一次加载可以正常工作,但是如果JSON文件中有更新,则胡子模板文件不会更新。
JSON:
{
"players": [{
"id": "1",
"player": "player one",
"count": "1"
}, {
"id": "2",
"player": "player two",
"count": "5"
}]
}
html:
<ul id="players" data-role="listview">
{{#players}}
<li>{{player}} {{count}}</li>
{{/players}}
</ul>
ajax:
setInterval(function(){
$.ajax({
type: "GET",
url: "json_players.php",
dataType: 'json',
complete: function() {
$('#players').listview().listview('refresh');
},
success: function(data) {
var template = $("#players").html();
var html = Mustache.render(template, data);
$('#players').html(html);
}
});
},2000);
如何更改我的代码? 谢谢!