RecordSet.filter( ) Method | Flash 6 |
filters records in a recordset |
A custom function that acts as a filter for the recordset.
A parameter that can be passed to the filter function as an argument.
A filtered RecordSet object.
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.
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.
RecordSet.sort( ), RecordSet.sortItemsBy( ); Chapter 3 and Chapter 4