如何在Dojo中使用Django for template标签?

Di Zou

我正在尝试在我的JavaScript中使用“ for” Django模板标记。Iam使用Dojo的DataGrid创建项目列表。这是我的代码:

<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>

但是,当我转到网页时,出现此错误:

Uncaught SyntaxError: Unexpected identifier

我在做什么错,我该如何解决?谢谢!

卡尔提克尔

您需要在字典中的值周围添加引号

data.items.push({ id: '{{ item.url }}_{{ item.id }}', col1: '{{ item.description }}' });

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章