javascript 只需从商店中检索所有记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18340026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 11:32:57  来源:igfitidea点击:

Simply retrieving all records from a store

javascriptextjsrowsstore

提问by Kurai Bankusu

Instead of retrieving a single row of data from my store, how can I modify the following code to retrieve all records?

我如何修改以下代码以检索所有记录,而不是从我的商店中检索单行数据?

var store = Ext.data.StoreManager.lookup('MyStore');
        store.setProxy({
            type: 'pagingmemory',
            data: store.getAt(0)
          });
        store.load();

Any thoughts?

有什么想法吗?

回答by Jeff Shaver

You can use store.getRange()or you can use store.data.items. For the getRange()call, passing no parameters just defaults to 0 and the last record in the store.

您可以使用store.getRange()或您可以使用store.data.items. 对于getRange()调用,不传递参数只是默认为 0 和存储中的最后一条记录。

回答by b.lopes

I think this is not complete true, since getRange()will retrieve all the records from a store first page.

我认为这并不完全正确,因为getRange()将从商店第一页检索所有记录。

If your store has pages of 50 records per page, then store.getRange()will give you only the first 50 records.

如果您的商店每页有 50 条记录,那么store.getRange()只会给您前 50 条记录。

回答by Kemal Uysal

store.getRange()

will only retrieve the page currently worked on if the grid is not defined to have a buffered store. Store can be set as buffered by:

如果网格未定义为具有缓冲存储,则只会检索当前处理的页面。可以通过以下方式将存储设置为缓冲:

(buffered: true)

But that will decrease the performance since the whole page will be buffered even if a single page will be retrieved.

但这会降低性能,因为即使检索单个页面也会缓冲整个页面。

The most efficient way that comes to my mind is:

我想到的最有效的方法是:

    var pageSize = store.pageSize // will return the page size.
    var totalCount = store.totalCount // This will return total no of items

    for (var i=0; i<(totalCount/pageSize)+1;i++) {
         store.loadPage(i) // this will set the current page of the store to i variable.  
         ....
         ....
    }

回答by Nick

This will reload the store with all records:

这将使用所有记录重新加载存储:

store.load({start:0, limit: store.totalCount, page:1});

Take all records from store:

从存储中获取所有记录:

var records = store.getRange();`