Extjs 获取所有商店记录 [英] Extjs get all store records

查看:30
本文介绍了Extjs 获取所有商店记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题.是否可以在将过滤器添加到存储时获取加载到存储中的所有记录?例如,如果我将 34 条记录加载到商店中,然后应用过滤器,结果只剩下 15 条记录,那么我可以在不清除过滤器的情况下获得那 34 条记录吗?

I have one question. Is it possible to get all records which are loaded in a store when the filters are being added to store? For example, if I load into the store 34 records and then apply filters and there is only 15 left, could I get those 34 records without clearing filters?

推荐答案

这最初是针对 Ext 4.2 回答的,其中 snapshot 是公开的并记录在案.现在已经没有了.这是 Ext 5 和 6 的更新.

This was originally answered for Ext 4.2, where snapshot was public and documented. It is gone nowadays. So here's an update for Ext 5 and 6.

一个班轮:

var allRecords = (store.getData().getSource() || store.getData()).getRange();

分解:

var data = store.getData();
// get unfiltered collection (will be null if the store has never been filtered)
var snapshot = data.getSource();
// pick the one that exists
var unfilteredCollection = snapshot || data;
// get items in an array
var allRecords = unfilteredCollection.getRange();

Store#getData 为您提供商店的收藏.

Store#getData gives you the store's collection.

集合#getSource 为您提供商店的源",即未过滤的集合——但前提是该集合已被过滤,否则返回 null.

在这两种情况下,您都会得到一个 Ext.util.Collection.使用 getRange 获取实际的项目数组.

In both cases, you'll get a Ext.util.Collection. Use getRange to get an actual array of items.

一个 getUnfiltered 方法是在 Ext 5 中的某个时候引入的(据我所知是 5.0.1,但目前 Ext 5 的文档处于离线状态......).它没有出现在 Ext 5 的第一个版本中,它在 Ext 6 中消失了.所以,好吧...不要使用它!除非你无缘无故地想把你的代码绑定到 Ext 5,否则使用上面的方法.

A getUnfiltered method was introduced at some point in Ext 5 (5.0.1 as far as I can tell, but docs for Ext 5 are offline at the moment...). It was not present in the first versions of Ext 5, and it was gone by Ext 6. So, well... Don't use it! Unless you want to tie your code to Ext 5 for no reasons, use the above method.

(原始答案)

整个加载的数据集存储在snapshot 商店的属性.

The whole loaded dataset is stored in the snapshot property of the store.

它只在需要时才创建.这意味着在将某些过滤器应用于商店之前,该属性将不可用.因此,要以安全的方式获取您想要的信息,请使用:

It is only created when needed though. That means that the property won't be available before some filters have been applied to the store. So to get the information you want in a safe way, use:

var allRecords = store.snapshot || store.data;

分机 4/5/6

(可能还有未来的版本)

您可以使用查询queryBy.

这似乎是更向前兼容的方法,因为与以前的方法相反,此 API 没有跨版本更改.

This seems to be the more forward compatible approach since, contrary to the previous methods, this API hasn't changed across versions.

不幸的是,这将遍历集合并产生额外的处理成本......根据您的集合的大小,这可能会或可能不会忽略不计.

Unfortunately, that will traverse the collection and incurs extra processing cost... Which may or may not be negligible depending of the size of your collection.

var allRecords = store
  .queryBy(function() { return true; }) // returns a collection
  .getRange(); // returns array of items

这篇关于Extjs 获取所有商店记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆