Django templates: inserting values ​​for javascript variables

I am trying to assign some javascript variables in a Django template.

I had a problem when the values ​​assigned by me are written to the page correctly (I see them in the page source), but still appear as null.

I'm doing it:

<script type="text/javascript">
  var coords = [];
  {% for i in item_list %}
    coords.push([ {{i.x}}, {{i.y}} ]);
  {% endfor %}
</script>

This is the source of the page that is being created:

coords.push([ -320.435118373, -149.333637576 ]);
coords.push([ -120.41321373 , -329.312376 ]);
...

This seems like absolutely correct javascript, however, using Firebug to view the value coords, this is what is produced:

[[null, null], [null, null], [null, null]...[null, null]]

So, it is obvious that each of the calls push()goes right and each time a new array of size 2 is added. However, for some reason, numeric literals are evaluated to null.

Does anyone know how I can use these values ​​correctly?

UPDATE: , , jQuery flot:

$.plot($('#mapWrapper'), coords, options);

, , , Django. , , $.plot.

+5
3

, . , . , jquery flot , , .

:

$.plot($('#mapWrapper'), coords, options);

:

$.plot($('#mapWrapper'), [coords], options);

​​.

, .

+3

, ( item_list, dicts "x" "y" ). - , , .

, , , , , ?

0

? , , ?

, Coords, :

coords.push({ "x":-320.435118373, "y":-149.333637576 });
coords.push({ "y":-120.41321373, "y":-329.312376 });

.

0

All Articles