3

我是 ExtJS 的新用户,我有一个问题。

我有一家汽车商店,我创建了一个带有按钮的菜单,以按品牌或型号查看所有汽车。
现在我想显示一个带有网格面板的窗口,其中包含特定品牌/型号的所有汽车。实际上,当我创建按钮时,我会这样做:

var aCarButton = Ext.create('Ext.Button', {
    text: aTextButton,
    handler: function() {
        var aResultWindow = new ResultWindow(aTextButton, myCarStore, 'Brand', aBrandValue);
        aResultWindow.create();
    }
});
aMenuPanel.add(aCarButton);

对于我的功能,我这样做:

function ResultWindow(aTitle, aStore, aFilter, aFilterValue) {
    this.myTitle = aTitle;
    this.myStore = aStore;
    this.myFilter = aFilter;
    this.myFilterValue = aFilterValue;
    this.myStore.filter(aFilter, aFilterValue); 
}

ResultWindow.prototype.create = function() {
    var grid = Ext.create('Ext.grid.Panel', {
        store: this.myStore,
        columns: [
            ...
        ]
    });
    var window = Ext.create('Ext.window.Window', {
        layout: 'fit',
        maximizable: true,
        title: this.myTitle,
        items: [ grid ],
        width: 1024,
        height: 768
    });
    window.show();
}

首先,我不确定这是展示我想要的东西的最佳方式。
其次,我有一个按钮可以显示所有汽车(无过滤器),但需要大约 2 分钟才能显示我所有的 12000 条记录。

所以我的第一个问题是知道我显示我想要的内容的解决方案是否正确?
我的第二个问题是否可以更快地显示所有汽车?

PS:如果我犯了一些错误,对不起我的英语。

4

1 回答 1

3

这当然是一种方法,但我认为这不是在 Ext 中做到这一点的最佳方法,我会在以下几行中做一些事情:

var aCarButton = Ext.create('Ext.Button', {
text: aTextButton,
handler: function() {
        myCarStore.filter('Brand', aBrandvalue);
        var win = Ext.create("Ext.window.Window", {
            title: aTextButton,
            layout: 'fit',
            maximizable: true,
            width: 1024,
            height: 768,
            items:[{
                xtype: 'grid',
                store: myCarStore,
                columns: [
                    ...
                ]
            }]
        });
        win.show();
});
aMenuPanel.add(aCarButton);

我只是为了示例而声明 Window 内联,我可能会选择包含网格的自定义 Window 和一些自定义函数来过滤网格,但是,要点:你不需要弄乱原型在这里,真的没有必要,如果你想要的只是控制你的窗口是如何创建的,那么define像这样:

Ext.define("CarsWindow", {
    extend: 'Ext.window.Window',
    items:[
        ...
    ],
    filterByBrand: function(brandValue){
        this.down('grid').getStore().filter('Brand', brandValue);
    },
    ...
});

然后您可以通过以下方式实例化它:

Ext.create("CarsWindow", { title: 'YourTitle', ...}).show();

对于您的第二个问题,有一种方法可以在 Ext 中显示大型数据集而不会损失太多性能,您可以设置buffered: true您的存储定义,然后在此调用“store.loadPage(1)”:store.buffered

希望有帮助。

于 2012-12-13T13:33:53.777 回答