如何循环内部的extjs XTemplate

Gih*_*ita 5 javascript extjs extjs4

我试图用extjs xtemplate循环一个数组并创建一个表

Ext.define('dataview_model', {
    extend    : 'Ext.data.Model',
    fields  : [
        {name: 'count',            type: 'string'},
        {name: 'maxcolumns',    type: 'string'},
        {name: 'maxrows',        type: 'string'},
        {name: 'numbers',        type: 'array'}
    ]
});

Ext.create('Ext.data.Store', {
    storeId : 'viewStore',
    model    : 'dataview_model',
    data    : [
        {count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']}
    ]
});

var tpl = new Ext.XTemplate(
    '<tpl for=".">',

        '<tpl if="count &gt; 0">',
            '<table class="view_table">',    
                '<tpl for="numbers">',    
                    '<tr>',
                        '<td>{.}</td>',
                    '</tr>',
                '</tpl>',    
            '</table>',
        '</tpl>',

    '</tpl>'
);

Ext.create('Ext.DataView', {
    width             : 500,
    height            : 200,
    renderTo          : Ext.getBody(),
    store             : Ext.getStore('viewStore'),
    tpl               : tpl    
});
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止的工作实例

http://jsfiddle.net/6HgCd/

我想要做的是一旦有5行就停止循环,并将其他值添加到第二列,如下所示

+----+ +----+
|    | |    |
+----+ +----+
+----+ +----+
|    | |    |
+----+ +----+
+----+
|    |
+----+
+----+
|    |
+----+
+----+
|    |
+----+
Run Code Online (Sandbox Code Playgroud)

知道如何做到这一点?

谢谢.

Krz*_*tof 2

我找不到仅使用模板的方法,但下面是我的解决方案,它使用模板和数据更改侦听器。

Ext.create('Ext.data.Store', {
    storeId : 'viewStore',
    model    : 'dataview_model',
    data    : [
        {count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']},
        {count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']}
    ],
    listeners: {
        datachanged: function(store) {
            store.data.each(function(record) {
                record.data.groupedNumbers = [];
                for (var i = 0, j = 0; i < record.data.count; ++i, j = i % record.data.maxrows) {
                    record.data.groupedNumbers[j] = record.data.groupedNumbers[j] || { row: j, numbers: [] };
                    record.data.groupedNumbers[j].numbers.push(record.data.numbers[i]);
                }
            });
        }
    }
});

var tpl = new Ext.XTemplate(
    '<tpl for=".">',

        '<tpl if="count &gt; 0">',
            '<table class="view_table" style="border: 1px solid black">',    
                '<tpl for="groupedNumbers">',    
                    '<tr>',
                        '<tpl for="numbers">', 
                            '<td>{.}</td>',
                        '</tpl>',
                    '</tr>',
                '</tpl>',    
            '</table>',
        '</tpl>',

    '</tpl>'
);
Run Code Online (Sandbox Code Playgroud)

工作演示:http://jsfiddle.net/6HgCd/2/