Coerce array of objects into selectedItems Array

I have a list in my mxml, and when I query the database I pull back an array of objects that should be hi lighted in the list. The trace in the function below prints one of the properties from the object fine, but it errors out on the next line.

When I trace on report.rsStat[x] as Array, it says null. How can I get each one of those objects into the selectedItems as an Array?

Or is there a better way to put all the objects in that array into the selectedItems so the proper items in the list are hi lighted?
if(report.rsStat.length > 0){
	var rssCursor:IViewCursor = this.rssCollection.createCursor();
	for (var x:String in report.rsStat)
	{
		
		if(rssCursor.findFirst(report.rsStat[x])){
			trace("VAR " + x + " " + report.rsStat[x].name);
			this.rsStat.selectedItems = report.rsStat[x] as Array; //ERROR here
			this.rsStat.dispatchEvent(new ListEvent(ListEvent.CHANGE));
		}
	}
}

Open in new window

hallikpapaAsked:
Who is Participating?
 
Jones911Connect With a Mentor Commented:
report.rsStat is an array correct?  Its an array of objects.  So report.rsStat[x].name is one of the items you want selected?  You can cast a single item to an array.

Try this.
 if(rssCursor.findFirst(report.rsStat[x])){
                        trace("VAR " + x + " " + report.rsStat[x].name);
                        var temp:Array = new Array();
                        temp[0] = report.rsStat[x];                    
                        this.rsStat.selectedItems = temp;
                        this.rsStat.dispatchEvent(new ListEvent(ListEvent.CHANGE));
                }

Open in new window

0
 
hallikpapaAuthor Commented:
Well, that got rid of my error, but it isn't highlighting the items in the list that is now contained in rsStat.selectedItems.

What am I doing wrong?
<mx:Binding source="rsStat.selectedItems" destination="selectedRSStat" />
...
...
...
<mx:FormItem direction="horizontal" label="Location(s):" required="true" enabled="{editMode}">
	<mx:List id="rsStat" 
		width="200"
		dataProvider="{rsStatCollection}"
		enabled="{this.rs.selectedIndex > -1}"
		toolTip="Hold CTRL key to select multiple Location"
		labelField="name"
		allowMultipleSelection="true"/>
</mx:FormItem>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.