I am using GAE and at some stage I decode a UTF8 string to then hand it over to an HTML file with Jinja2:
for i in report:
unique_channels.append(i[0][j].decode("utf8"))
template_values = {
"unique_channels" : unique_channels,
"result" : result
}
Now, when I use Jinja2 to iterate over this list of unicode strings, all is good. But when I pass this list to Javascript, Javascript throws an unexpected string error. I assume the reason is the u'xxx'/Unicode strings.
var unique_channels = {{ unique_channels }};
for (var i = 1; i < 11; i++) {
new_data.push({"Position" : i.toString()})
for (var k = unique_channels.length - 1; k >= 0; k--) {
new_data[i-1][unique_channels[k]] = 0;
}
};
How do I avoid this? Should I pass the list to javascript in a different way? Any suggestions?
EDIT: Second part where I use the unique_channels list:
{% for j in unique_channels %}
<br><input type="checkbox" class="checkbox" name="{{ j }}" value="{{ j }}" onclick="updateData();" checked> {{ j }}
{% endfor %}
This will be treated as string when I use json.dumps