User Guide
DataSet.find() 365
Parameters
searchValues An array that contains one or more field values to be found within the
current sort.
Returns
Returns true if the values are found; otherwise, returns false.
Description
Method; searches the current view of the collection for an item with the field values specified
by
searchValues. Which items are in the current view depends on any current filter and
range settings. If an item is found, it becomes the current item in the DataSet object.
The values specified by
searchValues must be in the same order as the field list specified by
the current sort (see the example below).
If the current sort is not unique, the record (transfer object) found is nondeterministic. If you
want to find the first or last occurrence of a transfer object in a nonunique sort, use
DataSet.findFirst() or DataSet.findLast().
Conversion of the data specified is based on the underlying field’s type. For example, if you
specify
["05-02-02"] as a search value, the underlying date field is used to convert the value
using the date’s
DataType.setAsString() method. If you specify [new
Date().getTime()]
, the date’s DataType.setAsNumber() method is used.
Example
The following example searches for an item in the current collection whose name and id fields
contain the values
"Bobby" and 105, respectively. If found, DataSet.getItemId() is used to
get the unique identifier for the item in the collection, and
DataSet.locateById() is used to
position the current iterator on that item.
var studentID:String = null;
student_ds.addSort("id", ["name","id"]);
// Locate the transfer object identified by "Bobby" and 105.
// Note that the order of the search fields matches those
// specified in addSort().
if (student_ds.find(["Bobby", 105])) {
studentID = student_ds.getItemId();
}
// Now use locateByID() to position the current iterator
// on the item in the collection whose ID matches studentID.
if (studentID != null) {
student_ds.locateById(studentID);
}
See also
DataSet.applyUpdates(), DataSet.getItemId(), DataSet.locateById()