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
.