【问题标题】:extjs xtemplate filter blank rowextjs xtemplate过滤空白行
【发布时间】:2013-03-11 23:48:21
【问题描述】:

我正在使用以下 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 过滤,但这些都没有成功。

【问题讨论】:

    标签: templates extjs filter blank-line


    【解决方案1】:

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

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

    这会解决你的问题!

    【讨论】:

    • 我会使用过滤器,但如果我在另一个视图(特别是蔬菜视图)中使用商店,我打算这样做,我将无法获得完整的商店内容。
    • 没关系,我知道我可以在渲染视图之前执行 clearFilter。我稍后会试试这个,让你知道它是如何工作的。格拉齐!
    猜你喜欢
    • 2019-08-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-06
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    相关资源
    最近更新 更多