S
S
sergey2018-03-21 00:57:51
JavaScript
sergey, 2018-03-21 00:57:51

Line break when parsing JSON, how to overcome?

I use metronic datatables:
JSON parses a cycle in which jang variables (left as an example one order.notes with which the problem arose)

var dataJSONArray = JSON.parse('[{% for order in orders %} ' +
'{"orderNotes":"{{ order.notes }}"}\n' +
'{% if not forloop.last %},{% endif %}' +
'{% endfor %}]');

the manager in the dzhang admin panel enters a comment, and if he uses enter, the transition to a new line, then when parsing I get an error: Uncaught SyntaxError: Invalid or unexpected token and datatables does not work.
I know that a similar trouble in js can be beaten with the .replace(/\n/g, " "); But how to apply it to the Dzhang variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2018-03-21
@sim3x

Make a human json into the view and stick it into the template
entirely

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question