Clear Up
SharpKit Reference

AbstractMixedCollection Class

Namespace: Ext.util

Base Types

System.Object

Constructors

Name Description
AbstractMixedCollection()
AbstractMixedCollection(AbstractMixedCollectionConfig)
AbstractMixedCollection(object, JsString) @event remove Fires when an item is removed from the collection. @param {Object} o The item being removed. @param {String} key (optional) The key associated with the removed item.

Methods

Name Description
add(JsString, object) Adds an item to the collection. Fires the {@link #add} event when complete. @param {String} key

The key to associate with the item, or the new item.

If a {@link #getKey} implementation was specified for this MixedCollection, or if the key of the stored items is in a property called id, the MixedCollection will be able to derive the key for the new item. In this case just pass the new item in this parameter.

@param {Object} o The item to add. @return {Object} The item added.
addAll(object) Adds all elements of an Array or an Object to the collection. @param {Object/Array} objs An Object containing properties which will be added to the collection, or an Array of values, each of which are added to the collection. Functions references will be added to the collection if
{@link #allowFunctions}
has been set to true.
clear() Removes all items from the collection. Fires the {@link #clear} event when complete.
clone() Creates a shallow copy of this collection @return {Ext.util.MixedCollection}
collect(JsString, JsString, bool) Collects unique values of a particular property in this MixedCollection @param {String} property The property to collect on @param {String} root Optional 'root' property to extract the first argument from. This is used mainly when summing fields in records, where the fields are all stored inside the 'data' object @param {Boolean} allowBlank (optional) Pass true to allow null, undefined or empty string values @return {Array} The unique values
contains(object) Returns true if the collection contains the passed Object as an item. @param {Object} o The Object to look for in the collection. @return {Boolean} True if the collection contains the Object as an item.
containsKey(JsString) Returns true if the collection contains the passed Object as a key. @param {String} key The key to look for in the collection. @return {Boolean} True if the collection contains the Object as a key.
createValueMatcher(JsString, bool, bool, bool) Returns a regular expression based on the given value and matching options. This is used internally for finding and filtering, and by Ext.data.Store#filter @private @param {String} value The value to create the regex for. This is escaped using Ext.escapeRe @param {Boolean} anyMatch True to allow any match - no regex start/end line anchors will be added. Defaults to false @param {Boolean} caseSensitive True to make the regex case sensitive (adds 'i' switch to regex). Defaults to false. @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
each(JsAction, object) Executes the specified function once for every item in the collection, passing the following arguments:
  • item : Mixed

    The collection item

  • index : Number

    The item's index

  • length : Number

    The total number of items in the collection

The function should return a boolean value. Returning false from the function will stop the iteration. @param {Function} fn The function to execute for each item. @param {Object} scope (optional) The scope (
this
reference) in which the function is executed. Defaults to the current item in the iteration.
eachKey(JsAction, object) Executes the specified function once for every key in the collection, passing each key, and its associated item as the first two parameters. @param {Function} fn The function to execute for each item. @param {Object} scope (optional) The scope (
this
reference) in which the function is executed. Defaults to the browser window.
extractValues(JsString, JsString) @private Extracts all of the given property values from the items in the MC. Mainly used as a supporting method for functions like sum and collect. @param {String} property The property to extract @param {String} root Optional 'root' property to extract the first argument from. This is used mainly when extracting field data from Model instances, where the fields are stored inside the 'data' object @return {Array} The extracted values
filter(object, object, bool, bool)

Filters the objects in this collection by a set of {@link Ext.util.Filter Filter}s, or by a single property/value pair with optional parameters for substring matching and case sensitivity. See {@link Ext.util.Filter Filter} for an example of using Filter objects (preferred). Alternatively, MixedCollection can be easily filtered by property like this:

  
//create a simple store with a few people defined
var people = new Ext.util.MixedCollection();
people.addAll([
{id: 1, age: 25, name: 'Ed'},
{id: 2, age: 24, name: 'Tommy'},
{id: 3, age: 24, name: 'Arne'},
{id: 4, age: 26, name: 'Aaron'}
]);
//a new MixedCollection containing only the items where age == 24
var middleAged = people.filter('age', 24);
            
* * @param {Ext.util.Filter[]/String} property A property on your objects, or an array of {@link Ext.util.Filter Filter} objects @param {String/RegExp} value Either string that the property values should start with or a RegExp to test against the property @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning @param {Boolean} caseSensitive (optional) True for case sensitive comparison (defaults to False). @return {Ext.util.MixedCollection} The new filtered collection
filterBy(JsAction, object) Filter by a function. Returns a new collection that has been filtered. The passed function will be called with each object in the collection. If the function returns true, the value is included otherwise it is filtered. @param {Function} fn The function to be called, it will receive the args o (the object), k (the key) @param {Object} scope (optional) The scope (
this
reference) in which the function is executed. Defaults to this MixedCollection. @return {Ext.util.MixedCollection} The new filtered collection
findBy(JsAction, object) Returns the first item in the collection which elicits a true return value from the passed selection function. @param {Function} fn The selection function to execute for each item. @param {Object} scope (optional) The scope (
this
reference) in which the function is executed. Defaults to the browser window. @return {Object} The first item in the collection which returned true from the selection function.
findIndex(JsString, object, JsNumber, bool, bool) Finds the index of the first matching object in this collection by a specific property/value. @param {String} property The name of a property on your objects. @param {String/RegExp} value A string that the property values should start with or a RegExp to test against the property. @param {Number} start (optional) The index to start searching at (defaults to 0). @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning. @param {Boolean} caseSensitive (optional) True for case sensitive comparison. @return {Number} The matched index or -1
findIndexBy(JsAction, object, JsNumber) Find the index of the first matching object in this collection by a function. If the function returns true it is considered a match. @param {Function} fn The function to be called, it will receive the args o (the object), k (the key). @param {Object} scope (optional) The scope (
this
reference) in which the function is executed. Defaults to this MixedCollection. @param {Number} start (optional) The index to start searching at (defaults to 0). @return {Number} The matched index or -1
first() Returns the first item in the collection. @return {Object} the first item in the collection..
get(object) Returns the item associated with the passed key OR index. Key has priority over index. This is the equivalent of calling {@link #getByKey} first, then if nothing matched calling {@link #getAt}. @param {String/Number} key The key or index of the item. @return {Object} If the item is found, returns the item. If the item was not found, returns undefined. If an item was found, but is a Class, returns null.
getAt(JsNumber) Returns the item at the specified index. @param {Number} index The index of the item. @return {Object} The item at the specified index.
getByKey(object) Returns the item associated with the passed key. @param {String/Number} key The key of the item. @return {Object} The item associated with the passed key.
getCount() Returns the number of items in the collection. @return {Number} the number of items in the collection.
getKey(object) MixedCollection has a generic way to fetch keys if you implement getKey. The default implementation simply returns
item.id
but you can provide your own implementation to return a different value as in the following examples:
  
// normal way
var mc = new Ext.util.MixedCollection();
mc.add(someEl.dom.id, someEl);
mc.add(otherEl.dom.id, otherEl);
//and so on
// using getKey
var mc = new Ext.util.MixedCollection();
mc.getKey = function(el){
return el.dom.id;
};
mc.add(someEl);
mc.add(otherEl);
// or via the constructor
var mc = new Ext.util.MixedCollection(false, function(el){
return el.dom.id;
});
mc.add(someEl);
mc.add(otherEl);
            
@param {Object} item The item for which to find the key. @return {Object} The key for the passed item.
getRange(JsNumber, JsNumber) Returns a range of items in this collection @param {Number} startIndex (optional) The starting index. Defaults to 0. @param {Number} endIndex (optional) The ending index. Defaults to the last item. @return {Array} An array of items
indexOf(object) Returns index within the collection of the passed Object. @param {Object} o The item to find the index of. @return {Number} index of the item. Returns -1 if not found.
indexOfKey(JsString) Returns index within the collection of the passed key. @param {String} key The key to find the index of. @return {Number} index of the key.
insert(JsNumber, JsString, object) Inserts an item at the specified index in the collection. Fires the {@link #add} event when complete. @param {Number} index The index to insert the item at. @param {String} key The key to associate with the new item, or the item itself. @param {Object} o (optional) If the second parameter was a key, the new item. @return {Object} The item inserted.
last() Returns the last item in the collection. @return {Object} the last item in the collection..
remove(object) Remove an item from the collection. @param {Object} o The item to remove. @return {Object} The item removed or false if no item was removed.
removeAll(JsArray) Remove all items in the passed array from the collection. @param {Array} items An array of items to be removed. @return {Ext.util.MixedCollection} this object
removeAt(JsNumber) Remove an item from a specified index in the collection. Fires the {@link #remove} event when complete. @param {Number} index The index within the collection of the item to remove. @return {Object} The item removed or false if no item was removed.
removeAtKey(JsString) Removed an item associated with the passed key fom the collection. @param {String} key The key of the item to remove. @return {Object} The item removed or false if no item was removed.
replace(JsString, object) Replaces an item in the collection. Fires the {@link #replace} event when complete. @param {String} key

The key associated with the item to replace, or the replacement item.

If you supplied a {@link #getKey} implementation for this MixedCollection, or if the key of your stored items is in a property called id, then the MixedCollection will be able to derive the key of the replacement item. If you want to replace an item with one having the same key value, then just pass the replacement item in this parameter.

@param o {Object} o (optional) If the first parameter passed was a key, the item to associate with that key. @return {Object} The new item.
sum(JsString, JsString, JsNumber, JsNumber) Collects all of the values of the given property and returns their sum @param {String} property The property to sum by @param {String} root Optional 'root' property to extract the first argument from. This is used mainly when summing fields in records, where the fields are all stored inside the 'data' object @param {Number} start (optional) The record index to start at (defaults to 0) @param {Number} end (optional) The record index to end at (defaults to -1) @return {Number} The total

Properties

Name Description
allowFunctions @cfg {Boolean} allowFunctions Specify true if the {@link #addAll} function should add function references to the collection. Defaults to false.
Count Returns the number of items in the collection. @return {Number} the number of items in the collection.
© Copyright 2005-2011 SharpKit. All rights reserved.