RecordSet.filter( )


RecordSet.filter( ) Method Flash 6

filters records in a recordset
   myRecordSet   .filter(   filterFunction   ,   context   ) 

Arguments

filterFunction

A custom function that acts as a filter for the recordset.

context

A parameter that can be passed to the filter function as an argument.

Returns

A filtered RecordSet object.

Description

The filter( ) method creates a second recordset by filtering an existing recordset using a custom filter function. This function can filter the recordset on any kind of criteria you prefer. You could, for example, filter a recordset by date, returning only those records that contain a field that is within a certain date range. You can filter any other criteria, such as length of a field, first letter of a field, or a certain word within a field.

The filtered recordset does not contain any reference or association to the original server-side recordset, such as paging. However, the new RecordSet object created by the filter( ) method contains references to rows in the original client-side Recordset object, not copies of that data. The filter( ) method also consumes memory and processing time, so it should be used sparingly.

The filter function that you define can accept one or two arguments. The first argument is a record to examine, and the second, optional argument can be used in your filter criteria. Each record of the original RecordSet object is passed to the filter function; if the filter function returns true , the record is added to the new, filtered RecordSet object.

Example

The following code demonstrates the filter( ) method:

 #include "RecordSet.as" var myRecordset_rs = new RecordSet(["First", "Last", "Email"]); myRecordset_rs.addItem({First:"Tom", Last:"Muck", Email:"tom@tom-muck.com"}); myRecordset_rs.addItem({First:"Jack", Last:"Splat", Email:"jack@tom-muck.com"}); myRecordset_rs.addItem({First:"Biff", Last:"Bop", Email:""}); function filterOnEmail(aRecord) {   return (aRecord.Email != ""); } var filteredRecordset_rs = myRecordset_rs.filter(filterOnEmail); trace(filteredRecordset_rs.getLength( )); 

In this case, three records are added to the initial RecordSet object. The filter function removes records that don't have email addresses. The new RecordSet object contains the two records that have email addresses, as shown in the Output window.

See Also

RecordSet. sort ( ) , RecordSet.sortItemsBy( ) ; Chapter 3 and Chapter 4



Flash Remoting
Flash Remoting: The Definitive Guide
ISBN: 059600401X
EAN: 2147483647
Year: 2003
Pages: 239
Authors: Tom Muck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net