This is my function:
function convert_strings() {
var chart_labels = {{ chartlabels }};
var array_length = chart_labels.length;
for (var i = 0; i < array_length; i++) {
chart_labels[i] = chart_labels[i].replace(/'/g, "'")
}
return chart_labels
}
This is my error: "Uncaught SyntaxError: Unexpected token &"
function convert_strings() {
var chart_labels = ['CHENNAI LPG RO', 'KOCHI LPG RO', 'BANGALORE LPG RO', 'HUBLI LPG RO', 'MADURAI LPG RO', 'MANGLORE LPG RO'];
var array_length = chart_labels.length;
for (var i = 0; i < array_length; i++) {
chart_labels[i] = chart_labels[i].replace(/'/g, "'")
}
return chart_labels
}
Please advice what to do :)
In the view, you can convert the chartlabels to a JSON blob, for example with:
import json
def some_view(request):
# ...
context['chartlabels_json'] = json.dumps(context['chartlabels'])
# ...
return render(request, 'some_template.html', context)
In the template, we can then write the blob in an unescaped way:
function convert_strings() {
return {{ chartlabels_json|safe }};
}
A more convenient way is however probably using the django-jsonify [PyPI] tool, and thus simply pass the charlabel through the jsonify filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With