I am working with a MVC model (django). I have a for loop in the template that collects data from a sqlite3 database. I need to fill a JavaScript variable (with JSON format) that splits radar.client
field from the database. This field is a comma-separated values string. I need to parse it into the json in different "children" values. Let me go into the practice now.
The code that generates the json var looks like:
var json = {
"id": "1",
"name": "Server",
"children": [
{% if clave_radar % }
{% for radar in clave_radar % }
{"id": "{{ radar.key }}",
"name": "{{ radar.ap }}",
"data": {"": "", "": ""},
"children": [
//This is where I need to split in different children
{"id": "1_{{ radar.key }}",
"name": "{{ radar.clients }}",
"data": {"": "", "": ""},
"children": []},
]},
{% endfor % }
{% endif % }
],
};
Now let me show you an example of how the processed code in the server looks like for the client:
var json_test={
"id": "1",
"name": "Server",
"children": [
{
"id": "13",
"name": "WLT",
"data": {"": "","": ""},
"children": [
{
"id": "1_13",
"name": "081196(Intel Corporate), 68a3c4(Liteon Technology Corporation), b8d9ce(Samsung Electronics)",
"data": {"": "","": ""},
"children": []
},
//Children Liteon and Samsung should appear here and not packed in 1_13
]
},
],
};
And this is how I am struggling to make it look like:
varjson_real={
"id": "1",
"name": "Server",
"children": [
{
"id": "13",
"name": "WLT",
"data": {"": "","": ""},
"children": [
{
"id": "1_13",
"name": "081196(Intel Corporate)",
"data": {"": "","": ""},
"children": []
},
{
"id": "2_13",
"name": "68a3c4(Liteon Technology Corporation)",
"data": {
"": "",
"": ""
},
"children": []
},
{
"id": "3_13",
"name": "b8d9ce(Samsung Electronics)",
"data": {"": "","": ""},
"children": []
},
]
},
]
};