admin管理员组文章数量:1326304
OK. My HTML looks like below.
<div id="json"></div>
<div id="content-placeholder">
<script id="some-template" type="text/x-handlebars-template">
<table>
<thead>
<th>col 1</th>
<th>col 2</th>
</thead>
<tbody>
{{#results}}
<tr>
<td>{{col_1}}</td>
<td>{{col_2}}</td>
</tr>
{{/results}}
</tbody>
</table>
</script>
</div>
And I am populating the above via Handlebar.js and the data is received from the server. Here's the code.
$.get(get_data_url, function(data)
{
$('#json').empty().append(data);
var rows = eval('(' + data + ')');
var source = $("#some-template").html();
var template = Handlebarspile(source);
$("#content-placeholder").empty().append(template(rows));
});
When the code runs the first time, it looks fine. But when I call the $.get the second time (and so forth), the template is not refreshed with the new data.
I also print out the whole data string in , to make sure that data is being refreshed from the server and it is.
When I check on my Chrome, it tells me "Uncaught TypeError: Cannot call method 'match' of null".
Is it something to do with "pile"?
OK. My HTML looks like below.
<div id="json"></div>
<div id="content-placeholder">
<script id="some-template" type="text/x-handlebars-template">
<table>
<thead>
<th>col 1</th>
<th>col 2</th>
</thead>
<tbody>
{{#results}}
<tr>
<td>{{col_1}}</td>
<td>{{col_2}}</td>
</tr>
{{/results}}
</tbody>
</table>
</script>
</div>
And I am populating the above via Handlebar.js and the data is received from the server. Here's the code.
$.get(get_data_url, function(data)
{
$('#json').empty().append(data);
var rows = eval('(' + data + ')');
var source = $("#some-template").html();
var template = Handlebars.pile(source);
$("#content-placeholder").empty().append(template(rows));
});
When the code runs the first time, it looks fine. But when I call the $.get the second time (and so forth), the template is not refreshed with the new data.
I also print out the whole data string in , to make sure that data is being refreshed from the server and it is.
When I check on my Chrome, it tells me "Uncaught TypeError: Cannot call method 'match' of null".
Is it something to do with "pile"?
Share Improve this question edited Aug 19, 2011 at 3:10 mu is too short 435k71 gold badges858 silver badges818 bronze badges asked Aug 19, 2011 at 3:04 ericbaeericbae 9,64426 gold badges77 silver badges109 bronze badges1 Answer
Reset to default 5The first time you do this:
$("#content-placeholder").empty()...
Your <div>
turns into this:
<div id="content-placeholder">
</div>
And your template is gone. Move your template:
<script id="some-template" type="text/x-handlebars-template">
...
</script>
to somewhere outside #content-placeholder
.
本文标签: javascriptHandlebarjs not refreshing my templateStack Overflow
版权声明:本文标题:javascript - Handlebar.js not refreshing my template - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742207768a2433138.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论