文档帮助

术语、图标和标签

许多类在使用配置对象创建(实例化)类时都有快捷名称。快捷名称被称为 alias(如果类扩展了 Ext.Component,则为 xtype)。alias/xtype 列在适用类的类名旁边,以便快速参考。

访问级别

框架类或其成员可以指定为 privateprotected。否则,该类/成员为 publicPublicprotectedprivate 是访问描述符,用于传达类或类成员应如何以及何时使用。

成员类型

成员语法

下面是一个类成员示例,我们可以对其进行剖析,以展示类成员的语法(在本例中是从 Ext.button.Button 类查看的 lookupComponent 方法)。

lookupComponent ( item ) : Ext.Component
protected

当原始配置对象添加到此容器时调用,无论是在初始化 items 配置期间,还是在添加新项目 added 或 {@link #insert 插入}时。

此方法将传递的对象转换为实例化的子组件。

当需要对子创建应用特殊处理时,可以在子类中重写此方法。

参数

item :  Object

正在添加的配置对象。

返回值
Ext.Component

要添加的组件。

让我们看一下成员行的每个部分

成员标志

API 文档使用许多标志来进一步传达类成员的功能和意图。标签可以用文本标签、缩写或图标表示。

类图标

- 表示框架类

- Singleton 框架类。*有关更多信息,请参阅 singleton 标志

- 组件类型的框架类(Ext JS 框架中扩展 Ext.Component 的任何类)

- 表示类、成员或指南在当前查看的版本中是新的

成员图标

- 表示类型为 config 的类成员

- 表示类型为 property 的类成员

- 表示类型为 method 的类成员

- 表示类型为 event 的类成员

- 表示类型为 theme variable 的类成员

- 表示类型为 theme mixin 的类成员

- 表示类、成员或指南在当前查看的版本中是新的

类成员快速导航菜单

在 API 文档页面上的类名正下方是一行按钮,对应于当前类拥有的成员类型。每个按钮显示按类型划分的成员计数(此计数在应用过滤器后会更新)。单击按钮将导航到该成员部分。将鼠标悬停在成员类型按钮上将显示该类型的所有成员的弹出菜单,以便快速导航。

Getter 和 Setter 方法

与类 config 选项相关的 Getter 和 Setter 方法将显示在方法部分以及 API 文档和成员类型菜单的 configs 部分中,就在它们所作用的 config 下方。Getter 和 Setter 方法文档将在 config 行中找到,以便于参考。

历史记录栏

您的页面历史记录保存在本地存储中,并显示在顶部标题栏正下方(使用可用的实际空间)。默认情况下,仅显示与您当前查看的产品/版本匹配的搜索结果。您可以通过单击历史记录栏右侧的 按钮并选择“全部”单选选项来展开显示的内容。这将显示历史记录栏中所有产品/版本的所有最近页面。

在历史记录配置菜单中,您还将看到最近访问页面的列表。结果按“当前产品/版本”和“全部”单选选项过滤。单击 按钮将清除历史记录栏以及本地存储中保存的历史记录。

如果在历史记录配置菜单中选择“全部”,则将启用“在历史记录栏中显示产品详细信息”复选框选项。选中后,每个历史页面的产品/版本将与历史记录栏中的页面名称一起显示。将光标悬停在历史记录栏中的页面名称上方也将显示产品/版本作为工具提示。

搜索和过滤器

可以使用页面顶部的搜索字段搜索 API 文档和指南。

在 API 文档页面上,还有一个过滤器输入字段,用于使用过滤器字符串过滤成员行。除了按字符串过滤外,您还可以按访问级别、继承和只读过滤类成员。这是使用页面顶部的复选框完成的。

API 类导航树底部的复选框过滤类列表,以包含或排除私有类。

单击空的搜索字段将显示您最近 10 次搜索,以便快速导航。

API 文档类元数据

每个 API 文档页面(JavaScript 原始类型页面除外)都有一个与该类相关的元数据菜单视图。此元数据视图将具有以下一项或多项

展开和折叠示例及类成员

可运行的示例 (Fiddles) 默认在页面上展开。您可以使用代码块左上角的箭头单独折叠和展开示例代码块。您还可以使用页面右上角的切换按钮切换所有示例的折叠状态。切换所有状态将在页面加载之间记住。

类成员默认在页面上折叠。您可以使用成员行左侧的箭头图标或右上角的展开/折叠所有切换按钮全局展开和折叠成员。

桌面 -vs- 移动视图

在较窄的屏幕或浏览器上查看文档将导致针对较小外形尺寸优化的视图。桌面和“移动”视图之间的主要区别是

查看类源代码

可以通过单击 API 文档页面顶部的类名来查看类源代码。可以通过单击成员行右侧的“查看源代码”链接来查看类成员的源代码。

GXT 4.x


顶部

ListStore

客户端记录列表。

  • 记录默认可见。
  • 所有操作通常在可见的记录列表上执行。
  • 过滤将隐藏可见记录。
  • <M> 泛型在 ListStore<M> 中表示 bean 模型。

参考

列表编辑器

有关将 ListStore 与编辑器一起使用的更多信息,请参阅 ListStoreEditor

实例化

使用 ModelKeyProvider<M> 初始化 ListStore<M>,它提供唯一的记录标识。

  • ModelKeyProvider<M>ListStore<M> 的必需构造函数参数。

  • 简单示例

      ListStore<MyData> listStore = ListStore(modelKeyProvider);
    

示例

ListStore可以使用 PropertyAccess 提供程序或匿名 ModelKeyProvider 初始化。

使用属性访问定义实例化

实例化 ListStore 需要 ModelKeyProvider,可以通过属性访问定义提供。有关更多信息,请参阅 PropertyAccess 定义配置。

  • 属性访问定义示例

      // Define the keyProvider as a property.
      public interface StockProperties extends PropertyAccess<Stock> {
        @Path("id")
        ModelKeyProvider<Stock> key();
      }
    
      // Instantiate the grid properties.
      private static final StockProperties gridProperties = GWT.create(StockProperties.class);
    
      // Instantiate the ListStore.
      ListStore<Stock> listStore = new ListStore<Stock>(gridProperties.key());
    

使用匿名 ModelKeyProvider 实例化

使用匿名 ModelKeyProvider 实例化 ListStore

  • 匿名 ModelKeyProvider 示例

      ListStore<Stock> listStore = new ListStore<Stock>(new ModelKeyProvider<Stock>() {
        @Override
        public String getKey(Stock item) {
          return String.valueOf(item.getId());
        }
      });
    

数据操作

下面列出了一些可以操作 ListStore 集合的操作。

添加

添加到 ListStores 集合。

  • 一些可用的方法

      // add an item
      listStore.add(item);
    
      // add item at the visible index
      boolean success = listStore.add(index, item);
    
      // add a collection
      boolean success = listStore.addAll(items);
    
      // add a collection starting at visible index
      boolean success = listStore.addAll(index, items);
    
      // replace all the items
      listStore.replaceAll(items);
    

过滤

过滤 ListStore 将隐藏可见项目。

  • 记录默认可见。
  • 过滤将隐藏可见记录。
  • 有关更多信息,请参阅 store filtering

  • 一些可用的方法

      // get the attached filters 
      LinkedHashSet<StoreFilter<Stock>> filters = listStore.getFilters();
    
      // are the filters enabled
      boolean enabled = listStore.isEnableFilters();
    
      // remove a filter
      listStore.removeFilter(StoreFilter<M> filter);
    
      // remove all the filters
      listStore.removeFilters();
    
      // enable or disable attached filters
      listStore.setEnableFilters(boolean enableFilters);
    
      // get all the attached filters
      LinkedHashSet<StoreFilter<Stock>> filters = listStore.getFilters();
    

获取

ListStore 获取数据。

  • 一些可用的方法

      // get the item at the visible index
      M item = listStore.get(index);
    
      // find the item based on its unique identifier. 
      M item = listStore.findModelWithKey(java.lang.String key);
    
      // gets all the items
      List<M> items = listStore.getAll();
    
      // find the visible index of an item
      int index = listStore.indexOf(item);
    
      // find a sublist of the visible items
      List<M> subItemsList = listStore.subList(int start, int end);
    
      // find the model in the list
      M model = listStore.findModel(M model);
    
      // do the models key match
      Boolean matching = listStore.hasMatchingKey(M model1, M model2);
    
      // find the keyProvider
      ModelKeyProvider<M> provider = listStore.getKeyProvider();
    
      // get the list store size of visible items
      listStore.size();        
    

移除

移除和清除 ListStore 中的数据。

  • 一些可用的方法

      // removes all the records.
      listStore.clear();
    
      // remove record from visible index
      M model = listStore.remove(index);
    
      // remove item matching model unique identifier
      boolean success = listStore.remove(item);
    

排序

ListStore 中的记录进行排序。

  • 有关更多信息,请参阅 store sorting

  • 一些可用的方法

      // add a sort
      listStore.addSortInfo(StoreSortInfo<M> info);
    
      // add a sort at index
      listStore.addSortInfo(int index, StoreSortInfo<M> info);
    
      // clear the sort
      listStore.clearSortInfo();
    
      // re-apply a sort
      listStore.applySort(boolean suppressEvent);
    
      // get the sort configuration        
      List<StoreSortInfo<Stock>> sortInfo = listStore.getSortInfo();
    

记录

ListStore 中使用记录。

  • 当 store.autocommit 为 false 时,可以使用记录操作。
  • 使用记录可以触发 StoreRecordChangeEventsStoreUpdateEvent 事件。

  • 一些可用的方法

      // does the record exist
      boolean hasRecord = listStore.hasRecord(M data);
    
      // Gets records with uncommitted changes
      Collection<Store<M>.Record> modifiedItems = listStore.getModifiedRecords();
    
      // Get the model record and if it doesn't exist it will create a record by default. 
      // Don't create a record by wrapping this with: if (listStore.hasRecord(M data)) { // get record } 
      ListStore<M>.Record record = listStore.getRecord(item);
    
      // commit changes to the model
      listStore.commitChanges();
    
      // is autocommit on
      boolean autoCommit = listStore.isAutoCommit();
    
      // Cancel changes
      listStore.rejectChanges();
    
      // autocommit will update the model immediately. Otherwise que changes
      listStore.setAutoCommit(boolean isAutoCommit);
    

更新

更新 ListStore 中的数据。

  • 一些可用的方法

      // replaces record matching model unique identifier
      listStore.update(item);
    

事件

StoreHandlers 一次添加大多数处理程序。尽管可以单独添加这些相同的处理程序。

  • 一些可用的方法

      // fire an event from the listStore.
      listStore.fireEvent(event);
    

StoreHandlers

这是 StoreHandlers 的一组。单个处理程序列在下面。

  • StoreHandlers 示例

      StoreHandlers<Stock> handlers = new StoreHandlers<Stock>() {
        @Override
        public void onAdd(StoreAddEvent<Stock> event) {
        }
    
        @Override
        public void onRemove(StoreRemoveEvent<Stock> event) {
        }
    
        @Override
        public void onFilter(StoreFilterEvent<Stock> event) {
        }
    
        @Override
        public void onClear(StoreClearEvent<Stock> event) {
        }
    
        @Override
        public void onUpdate(StoreUpdateEvent<Stock> event) {
        }
    
        @Override
        public void onDataChange(StoreDataChangeEvent<Stock> event) {
        }
    
        @Override
        public void onRecordChange(StoreRecordChangeEvent<Stock> event) {
        }
    
        @Override
        public void onSort(StoreSortEvent<Stock> event) {
        }
      };
      listStore.addStoreHandlers(handlers);
    

StoreAddEvent

  • 在添加时触发。

      listStore.addStoreAddHandler(new StoreAddHandler<Stock>() {
        @Override
        public void onAdd(StoreAddEvent<Stock> event) {
        }
      });
    

StoreRemoveEvent

  • 在记录移除时触发。

      listStore.addStoreRemoveHandler(new StoreRemoveHandler<Stock>() {
        @Override
        public void onRemove(StoreRemoveEvent<Stock> event) {
        }
      });
    

StoreUpdateEvent

  • 在记录更新时触发。

      listStore.addStoreUpdateHandler(new StoreUpdateHandler<Stock>() {
          @Override
          public void onUpdate(StoreUpdateEvent<Stock> event) {
          }
      });
    

StoreRecordChangeEvent

  • 在记录更改时触发。

      listStore.addStoreRecordChangeHandler(new StoreRecordChangeHandler<Stock>() {
          @Override
          public void onRecordChange(StoreRecordChangeEvent<Stock> event) {
          }
      });
    
  • 在更改后还原记录的示例。

      final DoubleField priceField = new DoubleField();
      priceField.addValidator(new MaxNumberValidator<Double>(99.99));
    
      // record whether the entry of the record was valid
      priceField.addInvalidHandler(new InvalidHandler() {
        @Override
        public void onInvalid(InvalidEvent event) {
          invalidPriceRecord = true;
        }
      });
      // record whether the entry of the record was valid
      priceField.addValidHandler(new ValidHandler() {
        @Override
        public void onValid(ValidEvent event) {
          invalidPriceRecord = false;
        }
      });
    
      // Listen for record changes and revert the incorrect entries.
      store.addStoreRecordChangeHandler(new StoreRecordChangeHandler<Plant>() {
        @Override
        public void onRecordChange(StoreRecordChangeEvent<Plant> event) {
          Store<Plant>.Record record = event.getRecord();
          // revert value if invalid
          if (invalidPriceRecord) {
            record.revert();
          }
        }
      });
    

StoreFilterEvent

  • 在过滤器选择时触发。

      listStore.addStoreFilterHandler(new StoreFilterHandler<Stock>() {
          @Override
          public void onFilter(StoreFilterEvent<Stock> event) {
          }
      });
    

StoreClearEvent

  • 在清除记录时触发。

      listStore.addStoreClearHandler(new StoreClearHandler<Stock>() {
          @Override
          public void onClear(StoreClearEvent<Stock> event) {
          }
      });
    

StoreDataChangeEvent

  • 在记录更改时触发。

      listStore.addStoreDataChangeHandler(new StoreDataChangeHandler<Stock>() {
          @Override
          public void onDataChange(StoreDataChangeEvent<Stock> event) {
          }
      });
    

StoreSortEvent

  • 在排序选择时触发。

      listStore.addStoreSortHandler(new StoreSortHandler<Stock>() {
          @Override
          public void onSort(StoreSortEvent<Stock> event) {    
          }
      });
    

GXT 4.x