Print Friendly

# Class YAHOO.widget.DS_JSArray

Package: | YAHOO.widget
Class: | DS_JSArray
Extends: | DataSource
Defined In: | autocomplete.js

Implementation of YAHOO.widget.DataSource using a native Javascript array as its live data source.

## Public Properties

Property | Defined By
--- | ---
| ERROR_DATANULL : String | DataSource
<static> Error message for null data responses.
| ERROR_DATAPARSE : String | DataSource
<static> Error message for data responses with parsing errors.
| data : Array | DS_JSArray
In-memory Javascript array of strings.
| maxCacheEntries : Number | DataSource
Max size of the local cache. Set to 0 to turn off caching. Caching is useful to reduce the number of server connect...
| queryMatchCase : Boolean | DataSource
Enables query case-sensitivity matching. If caching is on and queryMatchCase is true, queries will only return result...
| queryMatchContains : Boolean | DataSource
Use this to equate cache matching with the type of matching done by your live data source. If caching is on and query...
| queryMatchSubset : Boolean | DataSource
Enables query subset matching. If caching is on and queryMatchSubset is true, substrings of queries will return match...

## Public Methods

Method | Defined By
--- | ---
| DS_JSArray(`aData {String[]}`, [`oConfigs {Object}`]) | DS_JSArray
| doQuery(`oCallbackFn {HTMLFunction}`, `sQuery {String}`, `oParent {Object}`) : void | DS_JSArray
Queries the live data source defined by data for results. Results are passed back to a callback function.
| flushCache() : void | DataSource
Flushes cache.
| getResults(`oCallbackFn {HTMLFunction}`, `sQuery {String}`, `oParent {Object}`) : void | DataSource
Retrieves query results, first checking the local cache, then making the query request to the live data source as def...
| toString() : String | DataSource
Public accessor to the unique name of the DataSource instance.

## Public Events

Event | Defined By
--- | ---
| cacheFlushEvent : (`oSelf {Object}`) | DataSource
Fired when the local cache is flushed.
| cacheQueryEvent : (`oSelf {Object}`, `oParent {Object}`, `sQuery {String}`) | DataSource
Fired when a query is made to the local cache.
| dataErrorEvent : (`oSelf {Object}`, `oParent {Object}`, `sQuery {String}`, `sMsg {String}`) | DataSource
Fired when an error is encountered with the live data source.
| getCachedResultsEvent : (`oSelf {Object}`, `oParent {Object}`, `sQuery {String}`, `aResults {Object[]}`) | DataSource
Fired when data is retrieved from the local cache.
| getResultsEvent : (`oSelf {Object}`, `oParent {Object}`, `sQuery {String}`, `aResults {Object[]}`) | DataSource
Fired when data is retrieved from the live data source.
| queryEvent : (`oSelf {Object}`, `oParent {Object}`, `sQuery {String}`) | DataSource
Fired when a query is made to the live data source.

## Property Details

### ERROR_DATANULL

`public String ERROR_DATANULL`
<static> Error message for null data responses.
This property is defined by DataSource.

### ERROR_DATAPARSE

`public String ERROR_DATAPARSE`
<static> Error message for data responses with parsing errors.
This property is defined by DataSource.

### data

`public Array data`
In-memory Javascript array of strings.
This property is defined by DS_JSArray.

### maxCacheEntries

`public Number maxCacheEntries`
Max size of the local cache. Set to 0 to turn off caching. Caching is useful to reduce the number of server connections. Recommended only for data sources that return comprehensive results for queries or when stale data is not an issue.
This property is defined by DataSource.

### queryMatchCase

`public Boolean queryMatchCase`
Enables query case-sensitivity matching. If caching is on and queryMatchCase is true, queries will only return results for case-sensitive matches.
This property is defined by DataSource.

### queryMatchContains

`public Boolean queryMatchContains`
Use this to equate cache matching with the type of matching done by your live data source. If caching is on and queryMatchContains is true, the cache returns results that "contain" the query string. By default, queryMatchContains is set to false, meaning the cache only returns results that "start with" the query string.
This property is defined by DataSource.

### queryMatchSubset

`public Boolean queryMatchSubset`
Enables query subset matching. If caching is on and queryMatchSubset is true, substrings of queries will return matching cached results. For instance, if the first query is for "abc" susequent queries that start with "abc", like "abcd", will be queried against the cache, and not the live data source. Recommended only for DataSources that return comprehensive results for queries with very few characters.
This property is defined by DataSource.

## Constructor Details

### DS_JSArray

`public function DS_JSArray(`aData {String[]}`, [`oConfigs {Object}`])`
Parameters:

- `{String[]}` : aData
  In-memory Javascript array of simple string data.
- `{Object}` : oConfigs
  (optional) Object literal of config params.

## Method Details

### doQuery

`public function doQuery(`oCallbackFn {HTMLFunction}`, `sQuery {String}`, `oParent {Object}`)`
Queries the live data source defined by data for results. Results are passed back to a callback function.
Parameters:

- `{HTMLFunction}` : oCallbackFn
  Callback function defined by oParent object to which to return results.
- `{String}` : sQuery
  Query string.
- `{Object}` : oParent
  The object instance that has requested data.

Returns:

- `void`

This method is defined by DS_JSArray.

### flushCache

`public function flushCache()`
Flushes cache.
Parameters:

- None.

Returns:

- `void`

This method is defined by DataSource.

### getResults

`public function getResults(`oCallbackFn {HTMLFunction}`, `sQuery {String}`, `oParent {Object}`)`
Retrieves query results, first checking the local cache, then making the query request to the live data source as defined by the function doQuery.
Parameters:

- `{HTMLFunction}` : oCallbackFn
  Callback function defined by oParent object to which to return results.
- `{String}` : sQuery
  Query string.
- `{Object}` : oParent
  The object instance that has requested data.

Returns:

- `void`

This method is defined by DataSource.

### toString

`public function toString()`
Public accessor to the unique name of the DataSource instance.
Parameters:

- None.

Returns:

- `String`
  Unique name of the DataSource instance

This method is defined by DataSource.

## Event Details

### cacheFlushEvent

`public event cacheFlushEvent`
Fired when the local cache is flushed.
Subscribers will be called with the following parameters:

- `{Object}` : oSelf
  The DataSource instance

This event is defined by DataSource.

### cacheQueryEvent

`public event cacheQueryEvent`
Fired when a query is made to the local cache.
Subscribers will be called with the following parameters:

- `{Object}` : oSelf
  The DataSource instance.
- `{Object}` : oParent
  The requesting object.
- `{String}` : sQuery
  The query string.

This event is defined by DataSource.

### dataErrorEvent

`public event dataErrorEvent`
Fired when an error is encountered with the live data source.
Subscribers will be called with the following parameters:

- `{Object}` : oSelf
  The DataSource instance.
- `{Object}` : oParent
  The requesting object.
- `{String}` : sQuery
  The query string.
- `{String}` : sMsg
  Error message string

This event is defined by DataSource.

### getCachedResultsEvent

`public event getCachedResultsEvent`
Fired when data is retrieved from the local cache.
Subscribers will be called with the following parameters:

- `{Object}` : oSelf
  The DataSource instance.
- `{Object}` : oParent
  The requesting object.
- `{String}` : sQuery
  The query string.
- `{Object[]}` : aResults
  Array of result objects.

This event is defined by DataSource.

### getResultsEvent

`public event getResultsEvent`
Fired when data is retrieved from the live data source.
Subscribers will be called with the following parameters:

- `{Object}` : oSelf
  The DataSource instance.
- `{Object}` : oParent
  The requesting object.
- `{String}` : sQuery
  The query string.
- `{Object[]}` : aResults
  Array of result objects.

This event is defined by DataSource.

### queryEvent

`public event queryEvent`
Fired when a query is made to the live data source.
Subscribers will be called with the following parameters:

- `{Object}` : oSelf
  The DataSource instance.
- `{Object}` : oParent
  The requesting object.
- `{String}` : sQuery
  The query string.

This event is defined by DataSource.

Copyright © 2006 Jack Slocum. All rights reserved.