如何使用XTemplate在x次迭代后添加换行符

How to add a break (newline) after x iterations using XTemplate?

本文关键字:迭代 添加 换行符 何使用 XTemplate      更新时间:2023-09-26

我想在XTemplate中进行12次迭代后添加一个</br>。我尝试了很多方法,但都没能奏效。示例代码如下:

days = new Ext.XTemplate(
            '<b>Days of month</b>',
            '<table width="100%"><tr><td style="word-wrap:break-word;">',
            '<tpl for=".">',
            '<tpl for="data">',
            **'{% if (xindex % 12 === 0) { %}' +
                    '<br/>' +
                     '{% } %}',**
              ,'{fieldValue}',
            '</tpl>',
            '</tpl>', 
            '</td></tr></table>',

我尝试使用xindex,但它没有任何效果,也没有在12条记录后添加换行符。我做错了什么?

完整示例:

Ext.onReady(function() {
    var data = [1, 2, 3, 4, 5, 6];
    var tpl = new Ext.XTemplate([
        '<tpl for=".">',
            '{.}',
            '<tpl if="xindex % 2 === 0"><br /></tpl>',
        '</tpl>'
    ]);
    tpl.overwrite(Ext.getBody(), data);
});