You need to add quotes around the values in the dictionary
data.items.push({ id: '{{ item.url }}_{{ item.id }}', col1: '{{ item.description }}' });
Pergunta
I am trying to use the "for" Django template tag in my javascript. Iam using Dojo's DataGrid to create a list of items. This is my code:
<script type="text/javascript">
require(['dojox/grid/DataGrid' , 'dojo/data/ItemFileWriteStore' , 'dojo/dom' , 'dojo/domReady!'],
function(DataGrid, ItemFileWriteStore, dom){
/*set up data store*/
var data = {
identifier: "id",
items: []
};
{% for item in items_list %}
data.items.push({ id: {{ item.url }} + '_' + {{ item.id }}, col1: {{ item.description }} });
{% endfor %}
var store = new ItemFileWriteStore({data: data});
/*set up layout*/
var layout = [[
{'name': 'Description', 'field': 'id', 'width': '100px'}
]];
/*create a new grid*/
var grid = new DataGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px'
}, "grid");
/*Call startup() to render the grid*/
grid.startup();
});
</script>
However, when I go to my webpage, I get this error:
Uncaught SyntaxError: Unexpected identifier
What am I doing wrong and how do I fix it? Thanks!
Solução
You need to add quotes around the values in the dictionary
data.items.push({ id: '{{ item.url }}_{{ item.id }}', col1: '{{ item.description }}' });