打印版式

Class Ext.data.SimpleStore

Package:Ext.data
Class:SimpleStore
Extends:Store
Defined In:SimpleStore.js
Smaller help class to make creating Stores from Array data easier.

属性   -  方法   -  事件   -  设置选项

公共属性

此类没有公共属性。

公共方法

方法 定义对象
  SimpleStore(Object config) SimpleStore
  add(Ext.data.Record[] records) : void Store
Add Records to the Store and fires the add event.
  addEvents(Object object) : void Observable
将对象中没有的事件从给出的对象中复制过来。
  addListener(String eventName, Function handler, [Object scope], [Object options]) : void Observable
为该组件加入事件处理器函数
  clearFilter(Boolean suppressEvent) : void Store
Revert to a view of the Record cache with no filtering applied.
  commitChanges() : void Store
Commit all Records with outstanding changes. To handle updates for changes, subscribe to the Store's "update" event, ...
  each(Function fn, [Object scope]) : void Store
Calls the specified function for each of the Records in the cache.
  filter(String field, String/RegExp value) : Boolean Store
Filter the records by a specified property.
  filterBy(Function fn, [Object scope]) : void Store
Filter by a function. The specified function will be called with each record in this data source. If the function ret...
  fireEvent(String eventName, Object... args) : Boolean Observable
触发指定的事件, 并将参数传入(至少要有事件名称)。
  getAt(String index) : Ext.data.Record Store
Get the Record at the specified index.
  getById(String id) : Ext.data.Record Store
Get the Record with the specified id.
  getCount() : void Store
Gets the number of cached records. If using paging, this may not be the total size of the dataset. If the data objec...
  getModifiedRecords() : Ext.data.Record[] Store
Get all records modified since the last load, or since the last commit.
  getRange([Number startIndex], [Number endIndex]) : Ext.data.Record[] Store
Returns a range of Records between specified indices.
  getSortState() : void Store
Returns the sort state of the Store as an object with two properties: field {String} The name of the field by whic...
  getTotalCount() : void Store
Gets the total number of records in the dataset. If using paging, for this to be accurate, the data object used by t...
  hasListener(String eventName) : Boolean Observable
检查该对象是否拥有指定事件的侦听器
  indexOf(Ext.data.Record[] records) : Number Store
Get the index within the cache of the passed Record.
  indexOfId(String id) : Number Store
Get the index within the cache of the Record with the passed id.
  insert(Number index, Ext.data.Record[] records) : void Store
Inserts Records to the Store at the given index and fires the add event.
  load(Object options) : void Store
Loads the Record cache from the configured Proxy using the configured Reader. If using remote paging, then the first...
  loadData(Object data, [Boolean append]) : void Store
Loads data from a passed data block. A Reader which understands the format of the data must have been configured in t...
  on(String eventName, Function handler, [Object options]) : void Observable
为该组件加入事件处理器函数, addListener 的简写方式
  purgeListeners() : void Observable
从对象身上移除所有的侦听器
  rejectChanges() : void Store
Cancel outstanding changes on all changed records.
  reload([Object options]) : void Store
Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load ope...
  remove(Ext.data.Record record) : void Store
Remove a Record from the Store and fires the remove event.
  removeAll() : void Store
Remove all Records from the Store and fires the clear event.
  removeListener(String eventName, Function handler, [Object scope]) : void Observable
移除侦听器
  setDefaultSort(String fieldName, [String dir]) : void Store
Sets the default sort column and order to be used by the next load operation.
  sort(String fieldName, [String dir]) : void Store
Sort the Records. If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local...
  un(String eventName, Function handler, [Object scope]) : void Observable
移除侦听器, removeListener 的简写方式

公共事件

事件 定义对象
  add : (Store this, Ext.data.Record[] records, Number index) Store
Fires when Records have been added to the Store
  beforeload : (Store this, Object options) Store
Fires before a request is made for a new data object. If the beforeload handler returns false the load action will b...
  clear : (Store this) Store
Fires when the data cache has been cleared.
  datachanged : (Store this) Store
Fires when the data cache has changed, and a widget which is using this Store as a Record cache should refresh its view.
  load : (Store this, Ext.data.Record[] records, Object options) Store
Fires after a new set of Records has been loaded.
  loadexception : () Store
Fires if an exception occurs in the Proxy during loading. Called with the signature of the Proxy's "loadexception" ev...
  remove : (Store this, Ext.data.Record record, Number index) Store
Fires when Records have been removed from the Store
  update : (Store this, Ext.data.Record record, String operation) Store
Fires when Records have been updated

设置选项

设置选项 定义对象
  baseParams : Object Store
An object containing properties which are to be sent as parameters on any HTTP request
  data : Array SimpleStore
The multi-dimensional array of data
  fields : Array SimpleStore
An standard field array consisting of string name or object literal field definitions
  id : Number SimpleStore
The index in the array that be used for record ids. Leave blank to auto generate ids.
  proxy : Ext.data.DataProxy Store
The Proxy object which provides access to a data object.
  reader : Ext.data.Reader Store
The Reader object which processes the data object and returns an Array of Ext.data.record objects which are cached ke...
  remoteSort : boolean Store
True if sorting is to be handled by requesting the Proxy to provide a refreshed version of the data object in sorted ...
  sortInfo : Object Store
A config object in the format: {field: "fieldName", direction: "ASC|DESC"}

构造函数

SimpleStore

public function SimpleStore(Object config)
参数:
  • config : Object

方法详情

add

public function add(Ext.data.Record[] records)
Add Records to the Store and fires the add event.
参数:
  • records : Ext.data.Record[]
    An Array of Ext.data.Record objects to add to the cache.
返回:
  • void
This method is defined by Store.

addEvents

public function addEvents(Object object)
将对象中没有的事件从给出的对象中复制过来。给出的对象必须也继承于 Observable 对象此方法才会有效果。
参数:
  • object : Object
    要复制事件的源对象
返回:
  • void
This method is defined by Observable.

addListener

public function addListener(String eventName, Function handler, [Object scope], [Object options])
为组件添加一个事件监听器
参数:
  • eventName : String
    侦听事件的类型
  • handler : Function
    事件调用的方法
  • scope : Object
    (可选)处理函数执行的作用域。处理函数 "this" 的内容。
  • options : Object
    (可选)一个包含处理设置属性的对象。可以包含下列的属性:
    • scope {Object} 处理函数执行的作用域。处理函数 "this" 的内容。
    • delegate {String} 一个简单的选择器用来过滤目标或查找目标的子节点。
    • stopEvent {Boolean} 值为 True 时用来中止事件。那样将中止传播,并防止缺省动作。
    • preventDefault {Boolean} 值为 True 时用来防止缺省动作。
    • stopPropagation {Boolean} 值为 True 时用来中止事件传播。
    • normalized {Boolean} 值为 False 时向处理函数传递浏览器事件用以代替 Ext.EventObject 对象。
    • delay {Number} 当事件触发后启用处理函数的延迟微秒数。
    • single {Boolean} 值为 True 时将添加一个处理函数用来处理下个触发的事件,并在处理完后移除。
    • buffer {Number} 使处理函数计划在由 Ext.util.DelayedTask 指定的微秒数后执行。如果事件在延迟期间再次触发,原来的处理函数将不再启动,而是由新的计划代替。

    组合选项
    使用选项参数可以组合不同类型的监听器:

    下面是一个标准的、延迟执行的、一次性的监听器,将会自动停止事件并传递一个自定义的参数(forumId)

    代码:
    el.on('click', this.onClick, this, { single: true, delay: 100, stopEvent : true, forumId: 4 });

    这个方法也允许传递的单个参数是一个包含多个指定处理函数的设置对象。

    一次调用多个处理函数
    代码:

    el.on({ 'click' : { fn: this.onClick scope: this, delay: 100 }, 'mouseover' : { fn: this.onMouseOver scope: this }, 'mouseout' : { fn: this.onMouseOut scope: this } });

    或者简写为:
    代码:

    el.on({ 'click' : this.onClick, 'mouseover' : this.onMouseOver, 'mouseout' : this.onMouseOut scope: this });
返回:
  • void
This method is defined by Observable.

clearFilter

public function clearFilter(Boolean suppressEvent)
Revert to a view of the Record cache with no filtering applied.
参数:
  • suppressEvent : Boolean
    If true the filter is cleared silently without notifying listeners
返回:
  • void
This method is defined by Store.

commitChanges

public function commitChanges()
Commit all Records with outstanding changes. To handle updates for changes, subscribe to the Store's "update" event, and perform updating when the third parameter is Ext.data.Record.COMMIT.
参数:
  • 无。
返回:
  • void
This method is defined by Store.

each

public function each(Function fn, [Object scope])
Calls the specified function for each of the Records in the cache.
参数:
  • fn : Function
    The function to call. The Record is passed as the first parameter. Returning false aborts and exits the iteration.
  • scope : Object
    (可选) The scope in which to call the function (defaults to the Record).
返回:
  • void
This method is defined by Store.

filter

public function filter(String field, String/RegExp value)
Filter the records by a specified property.
参数:
  • field : String
    A field on your records
  • value : String/RegExp
    Either a string that the field should start with or a RegExp to test against the field
返回:
  • Boolean
    True if the filter matched at least one record, else false
This method is defined by Store.

filterBy

public function filterBy(Function fn, [Object scope])
Filter by a function. The specified function will be called with each record in this data source. If the function returns true the record is included, otherwise it is filtered.
参数:
  • fn : Function
    The function to be called, it will receive 2 args (record, id)
  • scope : Object
    (可选) The scope of the function (defaults to this)
返回:
  • void
This method is defined by Store.

fireEvent

public function fireEvent(String eventName, Object... args)
触发指定的事件并给出参数(至少要有事件名称)。
参数:
  • eventName : String
  • args : Object...
    传入处理函数的参数
返回:
  • Boolean
    如果任何处理函数返回 false 则返回值为 false, 否则返回 true。
This method is defined by Observable.

getAt

public function getAt(String index)
Get the Record at the specified index.
参数:
  • index : String
    The index of the Record to find.
返回:
  • Ext.data.Record
    The Record at the passed index. Returns undefined if not found.
This method is defined by Store.

getById

public function getById(String id)
Get the Record with the specified id.
参数:
  • id : String
    The id of the Record to find.
返回:
  • Ext.data.Record
    The Record with the passed id. Returns undefined if not found.
This method is defined by Store.

getCount

public function getCount()
Gets the number of cached records.

If using paging, this may not be the total size of the dataset. If the data object used by the Reader contains the dataset size, then the getTotalCount() function returns the data set size

参数:
  • 无。
返回:
  • void
This method is defined by Store.

getModifiedRecords

public function getModifiedRecords()
Get all records modified since the last load, or since the last commit.
参数:
  • 无。
返回:
  • Ext.data.Record[]
    An array of Records containing outstanding modifications.
This method is defined by Store.

getRange

public function getRange([Number startIndex], [Number endIndex])
Returns a range of Records between specified indices.
参数:
  • startIndex : Number
    (可选) The starting index (defaults to 0)
  • endIndex : Number
    (可选) The ending index (defaults to the last Record in the Store)
返回:
  • Ext.data.Record[]
    An array of Records
This method is defined by Store.

getSortState

public function getSortState()
Returns the sort state of the Store as an object with two properties:

 field {String} The name of the field by which the Records are sorted
 direction {String} The sort order, "ASC" or "DESC"
参数:
  • 无。
返回:
  • void
This method is defined by Store.

getTotalCount

public function getTotalCount()
Gets the total number of records in the dataset.

If using paging, for this to be accurate, the data object used by the Reader must contain the dataset size

参数:
  • 无。
返回:
  • void
This method is defined by Store.

hasListener

public function hasListener(String eventName)
检查该对象是否拥有指定事件的侦听器
参数:
  • eventName : String
    查询事件之名称
返回:
  • Boolean
    值为 True 值表示事件监听器存在, 否则值为 false。
This method is defined by Observable.

indexOf

public function indexOf(Ext.data.Record[] records)
Get the index within the cache of the passed Record.
参数:
  • records : Ext.data.Record[]
    An Array of Ext.data.Record objects to add to the cache.
返回:
  • Number
    The index of the passed Record. Returns -1 if not found.
This method is defined by Store.

indexOfId

public function indexOfId(String id)
Get the index within the cache of the Record with the passed id.
参数:
  • id : String
    The id of the Record to find.
返回:
  • Number
    The index of the Record. Returns -1 if not found.
This method is defined by Store.

insert

public function insert(Number index, Ext.data.Record[] records)
Inserts Records to the Store at the given index and fires the add event.
参数:
  • index : Number
    The start index at which to insert the passed Records.
  • records : Ext.data.Record[]
    An Array of Ext.data.Record objects to add to the cache.
返回:
  • void
This method is defined by Store.

load

public function load(Object options)
Loads the Record cache from the configured Proxy using the configured Reader.

If using remote paging, then the first load call must specify the start and limit properties in the options.params property to establish the initial position within the dataset, and the number of Records to cache on each read from the Proxy.

It is important to note that for remote data sources, loading is asynchronous, and this call will return before the new data has been loaded. Perform any post-processing in a callback function, or in a "load" event handler.

参数:
  • options : Object
    An object containing properties which control loading options:
     params {Object} An object containing properties to pass as HTTP parameters to a remote data source. callback {Function} A function to be called after the Records have been loaded. The callback is passed the following arguments: r : Ext.data.Record[] options: Options object from the load call success: Boolean success indicator scope {Object} Scope with which to call the callback (defaults to the Store object) append {Boolean} indicator to append loaded records rather than replace the current cache. 
返回:
  • void
This method is defined by Store.

loadData

public function loadData(Object data, [Boolean append])
Loads data from a passed data block. A Reader which understands the format of the data must have been configured in the constructor.
参数:
  • data : Object
    The data block from which to read the Records. The format of the data expected is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
  • append : Boolean
    (可选) True to append the new Records rather than replace the existing cache.
返回:
  • void
This method is defined by Store.

on

public function on(String eventName, Function handler, [Object options])
为该组件加入事件处理器函数, addListener 的简写方式
参数:
  • eventName : String
    侦听事件的类型
  • handler : Function
    事件调用的方法
  • options : Object
    (可选)
返回:
  • void
This method is defined by Observable.

purgeListeners

public function purgeListeners()
从对象身上移除所有的侦听器
参数:
  • 无。
返回:
  • void
This method is defined by Observable.

rejectChanges

public function rejectChanges()
Cancel outstanding changes on all changed records.
参数:
  • 无。
返回:
  • void
This method is defined by Store.

reload

public function reload([Object options])
Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed.
参数:
  • options : Object
    (可选) An object containing properties which may override the options used in the last load operation. See load for details (defaults to null, in which case the most recently used options are reused).
返回:
  • void
This method is defined by Store.

remove

public function remove(Ext.data.Record record)
Remove a Record from the Store and fires the remove event.
参数:
  • record : Ext.data.Record
    Th Ext.data.Record object to remove from the cache.
返回:
  • void
This method is defined by Store.

removeAll

public function removeAll()
Remove all Records from the Store and fires the clear event.
参数:
  • 无。
返回:
  • void
This method is defined by Store.

removeListener

public function removeListener(String eventName, Function handler, [Object scope])
移除侦听器
参数:
  • eventName : String
    侦听事件的类型
  • handler : Function
    删除的处理函数
  • scope : Object
    (可选) The scope (this object) for the handler
返回:
  • void
This method is defined by Observable.

setDefaultSort

public function setDefaultSort(String fieldName, [String dir])
Sets the default sort column and order to be used by the next load operation.
参数:
  • fieldName : String
    The name of the field to sort by.
  • dir : String
    (可选) The sort order, "ASC" or "DESC" (defaults to "ASC")
返回:
  • void
This method is defined by Store.

sort

public function sort(String fieldName, [String dir])
Sort the Records. If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local sorting is used, the cache is sorted internally.
参数:
  • fieldName : String
    The name of the field to sort by.
  • dir : String
    (可选) The sort order, "ASC" or "DESC" (defaults to "ASC")
返回:
  • void
This method is defined by Store.

un

public function un(String eventName, Function handler, [Object scope])
移除侦听器, removeListener 的简写方式
参数:
  • eventName : String
    侦听事件的类型
  • handler : Function
    删除的处理函数
  • scope : Object
    (可选) The scope (this object) for the handler
返回:
  • void
This method is defined by Observable.

事件详情

add

public event add
Fires when Records have been added to the Store
Subscribers will be called with the following parameters:
  • this : Store
  • records : Ext.data.Record[]
    The array of Records added
  • index : Number
    The index at which the record(s) were added
This event is defined by Store.

beforeload

public event beforeload
Fires before a request is made for a new data object. If the beforeload handler returns false the load action will be canceled.
Subscribers will be called with the following parameters:
  • this : Store
  • options : Object
    The loading options that were specified (see load for details)
This event is defined by Store.

clear

public event clear
Fires when the data cache has been cleared.
Subscribers will be called with the following parameters:
  • this : Store
This event is defined by Store.

datachanged

public event datachanged
Fires when the data cache has changed, and a widget which is using this Store as a Record cache should refresh its view.
Subscribers will be called with the following parameters:
  • this : Store
This event is defined by Store.

load

public event load
Fires after a new set of Records has been loaded.
Subscribers will be called with the following parameters:
  • this : Store
  • records : Ext.data.Record[]
    The Records that were loaded
  • options : Object
    The loading options that were specified (see load for details)
This event is defined by Store.

loadexception

public event loadexception
Fires if an exception occurs in the Proxy during loading. Called with the signature of the Proxy's "loadexception" event.
Subscribers will be called with the following parameters:
  • 无。
This event is defined by Store.

remove

public event remove
Fires when Records have been removed from the Store
Subscribers will be called with the following parameters:
  • this : Store
  • record : Ext.data.Record
    The Record that was removed
  • index : Number
    The index at which the record was removed
This event is defined by Store.

update

public event update
Fires when Records have been updated
Subscribers will be called with the following parameters:
  • this : Store
  • record : Ext.data.Record
    The Record that was updated
  • operation : String
    The update operation being performed. Value may be one of:
     Ext.data.Record.EDIT Ext.data.Record.REJECT Ext.data.Record.COMMIT 
This event is defined by Store.

设置详情

baseParams

baseParams : Object
An object containing properties which are to be sent as parameters on any HTTP request
This config option is defined by Store.

data

data : Array
The multi-dimensional array of data
This config option is defined by SimpleStore.

fields

fields : Array
An standard field array consisting of string name or object literal field definitions
This config option is defined by SimpleStore.

id

id : Number
The index in the array that be used for record ids. Leave blank to auto generate ids.
This config option is defined by SimpleStore.

proxy

proxy : Ext.data.DataProxy
The Proxy object which provides access to a data object.
This config option is defined by Store.

reader

reader : Ext.data.Reader
The Reader object which processes the data object and returns an Array of Ext.data.record objects which are cached keyed by their id property.
This config option is defined by Store.

remoteSort

remoteSort : boolean
True if sorting is to be handled by requesting the Proxy to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
This config option is defined by Store.

sortInfo

sortInfo : Object
A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
This config option is defined by Store.

Ext - Copyright © 2006-2007 Ext JS, LLC
All rights reserved.