ActionScript 2.0 Components Language Reference |
|
|
|
| List component > List.dataProvider | |||
Flash Player 6 (6.0.79.0).
Flash MX 2004.
listInstance.dataProvider
Property; the data model for items viewed in a list. The value of this property can be an array or any object that implements the DataProvider API. The default value is []. For more information, see DataProvider API.
The List component, like other data-aware components, adds methods to the Array object's prototype so that they conform to the DataProvider API. Therefore, any array that exists at the same time as a list automatically has all the methods (addItem(), getItemAt(), and so on) it needs to be the data model for the list, and can be used to broadcast model changes to multiple components.
If the array contains objects, the List.labelField or List.labelFunction properties are accessed to determine what parts of the item to display. The default value is "label", so if a label field exists, it is chosen for display; if it doesn't exist, a comma-separated list of all fields is displayed.
|
NOTE |
If the array contains strings at each index, and not objects, the list is not able to sort the items and maintain the selection state. Any sorting causes the selection to be lost. |
Any instance that implements the DataProvider API can be a data provider for a List component. This includes Flash Remoting recordsets, Firefly data sets, and so on.
The following example uses an array of strings to populate the list:
my_list.dataProvider = ["Ground Shipping", "2nd Day Air", "Next Day Air"];
This example creates a data provider array and assigns it to the dataProvider property, as in the following:
var myDP_array:Array = new Array();
my_list.dataProvider = myDP_array;
var accounts_array:Array = new Array();
accounts_array.push({name:"checkings", accountID:12345});
accounts_array.push({name:"savings", accountID:67890});
for (var i:Number = 0; i < accounts_array.length; i++) {
// These changes to the data provider will be broadcast to the list.
myDP_array.addItem({label:accounts_array[i].name, data:accounts_array[i].accountID});
}
|
|
|
|