extjs xtemplate过滤器空白行

时间:2013-03-11 03:03:38

标签: templates extjs filter blank-line

我正在使用以下Xtemplate按类别过滤掉项目(请参阅下面“收纳”的视图/面板):

itemTpl: new Ext.XTemplate(
    '<tpl for=".">',
        '<tpl if="category === \'vegetable\'">',
            '<a href="" target="">{str}</a>',
        '</tpl>',
    '</tpl>'),

它按预期过滤(好吧,至少部分过滤)。

我有以下商店:

Ext.define("Produce.store.List", {
    extend: 'Ext.data.Store',
    alias: 'store.List',
    config: {
        model: 'Produce.model.Food',
        sorters: 'category',
        grouper: function(record) {
            return record.get('category')[0];
        },
        data: [
        { category: 'fruit', str: 'tomato'},
        { category: 'fruit', str: 'green bean'},
        { category: 'vegetable', str: 'celery'},
        { category: 'vegetable', str: 'sprouts'},
        { category: 'fruit', str: 'squash'},
        { category: 'fruit', str: 'snap peas'},
        { category: 'vegetable', str: 'rhubarb'},
        { category: 'vegetable', str: 'cabbage'}

        ]
    }
});

Xtemplate在以下视图/面板中呈现:

Ext.define('Produce.view.Vegetable', {
    extend: 'Ext.tab.Panel',
    requires: ['Produce.model.Food'],
    config: {
        tabBar: {
            docked: 'top',
            ui: 'neutral',
            layout: {
                pack: 'center'
            }
        },
        items: [{
            title: 'Produce',
            layout: Ext.os.deviceType == 'Phone' ? 'fit' : {
                type: 'vbox',
                align: 'center',
                pack: 'center'
            },
            cls: 'demo-list',
            items: [{
                width: Ext.os.deviceType == 'Phone' ? null : 300,
                height: Ext.os.deviceType == 'Phone' ? null : 500,
                xtype: 'list',
                store: 'List',
        itemTpl: new Ext.XTemplate(
        '<tpl for=".">',
            '<tpl if="category === \'vegetable\'">',
                '<a href="" target="">{str}</a>',
            '</tpl>',
        '</tpl>'),
               variableHeights: false
            }]
    }
});

当我运行时,只有商店中的蔬菜显示在面板中 - 这很棒 - 但是还会显示空白行,其中水果项目在渲染列表中被过滤掉 - 这不是很好。 (同样,在我的“水果”视图中,水果会根据需要显示,但如果有蔬菜,则显示空白行)。

如何摆脱这些空白行(这是一个问题,因为我的列表中的水果和蔬菜只是为了让应用程序正常工作,并且是一个填充来代表更多数量的记录被归类为我的实际应用程序)。我尝试使用Ext.IsEmpty并按null过滤,但这些都没有成功。

1 个答案:

答案 0 :(得分:0)

View运行良好:它为每条记录显示一行。您应该尝试将已过滤的商店添加到列表中。

查看Ext.util.Filter中的Sencha Touch documentation

这将解决您的问题!