RecordSet.filter

Availability

Usage

RecordSet.filter(filterFunction, context)

Parameters

Parameter
Description
filterFunction
An ActionScript function that takes one or two parameters and returns true or false. The first parameter is a single record from the RecordSet object. The second, optional, parameter is a context value that the function uses to determine whether to include the record in the result. The function must return true if the record should be included in the result RecordSet object.
context
A context value supplied by the caller. This value is the second parameter to the filter function.

Return value

A new RecordSet object that contains a reference, not a copy, to all the records that were selected by the filterFunction function.

Description

Method. Creates a new RecordSet object by calling the filterFunction function once for each record in the RecordSet object and collecting all records, for which the filterFunction function returns true, into a new RecordSet object. The order of the records in the new RecordSet object is the same as their order in the original RecordSet object. The order in which the original RecordSet object is traversed during the filtering process is not defined.

If used on a RecordSet object that is not fully-populated, only the currently available records are filtered. The new RecordSet object does not inherit the original RecordSet object's list of views, nor any association with a server-side RecordSet object.

Example

The following example demonstrates how to build a ListBox UI component that shows a filtered view of a RecordSet object:

#include "NetServices.as"
var allFlights =new RecordSet(["flight","numberOfStops"]);
allFlights.addItem({flight: "123", numberOfStops: 0});
allFlights.addItem({flight: "321", numberOfStops: 3});
allFlights.addItem({flight: "456", numberOfStops: 1});
allFlights.addItem({flight: "654", numberOfStops: 2});
function flightFilter(aRecord, requestedNumberOfStops)
{
  return (aRecord.numberOfStops <= requestedNumberOfStops);
}
myListBox.setDataProvider(allFlights.filter(flightFilter, 2));

See also

RecordSet.addView, RecordSet.sort

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flashremoting/mx/Using_Flash_Remoting_MX/asDict30.htm