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

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

问题描述

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

解决方案

编辑:这最初是针对Ext 4.2进行了回答,其中快照已被公开和记录。现在已经走了所以这里是Ext 5和6的更新。



Ext 5/6



一个班:

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

分解:

 code> var data = store.getData(); 
//获取未过滤的集合(如果存储从未被过滤,则为null)
var snapshot = data.getSource();
//选择一个存在
var unfilteredCollection = snapshot ||数据;
//获取数组中的项
var allRecords = unfilteredCollection.getRange();

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



集合#getSource 为您提供商店的源,即未过滤的集合,但只有收集已被过滤,否则返回 null



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



Ext 5 getUnfiltered 方法



一个 getUnfiltered 方法是在Ext 5(5.0.1)中引入的,据我所知,但Ext 5的文档目前正在离线...)。 Ext 5的第一个版本不存在,Ext 6已经不在了。所以,好吧,不要使用它!除非你没有理由将你的代码绑定到Ext 5,请使用上述方法。



Ext 4



(原始答案)



整个加载的数据集存储在 快照



仅在需要时创建。这意味着在某些过滤器应用于商店之前该属性将不可用。所以要以安全的方式获取所需的信息,请使用:

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



Ext 4/5/6





您可以使用 查询 queryBy / a>。



这似乎是更前进的兼容方式,因为与以前的方法相反,这个API在版本之间没有改变。



不幸的是,这将遍历收藏,并招致额外的处理成本...根据您的收藏大小,这可能是或可能不会忽略不计。

  var allRecords = store 
.queryBy(function(){return true;})//返回一个集合
.getRange (); //返回项目数组


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?

解决方案

Edit: 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.

Ext 5 / 6

One liner:

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

Decomposition:

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 gives you the store's collection.

Collection#getSource gives you the store's "source", that is the unfiltered collection -- but only if the collection has already been filtered, otherwise it returns null.

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

Ext 5 getUnfiltered method

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.

Ext 4

(original answer)

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;

Ext 4 / 5 / 6

(and probably future versions)

You can use query or queryBy.

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天全站免登陆