如何循环内部的extjs XTemplate

时间:2011-12-26 11:58:52

标签: 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    
});

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

http://jsfiddle.net/6HgCd/

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

+----+ +----+
|    | |    |
+----+ +----+
+----+ +----+
|    | |    |
+----+ +----+
+----+
|    |
+----+
+----+
|    |
+----+
+----+
|    |
+----+

知道怎么做吗?

感谢。

1 个答案:

答案 0 :(得分:1)

var tpl = new Ext.XTemplate(
'<tpl for=".">',
    '<table class="view_table">',
        '<tr>',    
            '<tpl for="numbers">',        
                '<td>{.}</td>',            
                '<tpl if="xindex % 5 === 0">',            
                    '</tr><tr>',                
                '</tpl>',            
            '</tpl>',        
        '</tr>',    
    '</table>',
'</tpl>'    
);

http://jsfiddle.net/6HgCd/4/