开发者

In Flash Builder, how do I make a <s:List> dataprovider="certain part of an Array"?

开发者 https://www.devze.com 2023-02-17 07:13 出处:网络
I have a List, and I have an ArrayCollection. The ArrayCollection is something like: <mx:ArrayCollection id=\"arrColl\">

I have a List, and I have an ArrayCollection.

The ArrayCollection is something like:

<mx:ArrayCollection id="arrColl">

<mx:source>

<mx:Array>

<mx:Object label="Student A" score="85,36,43,67,54,47" />

<mx:Object label="Student B" score="85,36,43,67,54,47" />

<mx:Object label="Student C" score="85,36,43,67,54,47" />

</mx:Array>

</mx:source>

</mx:ArrayCollection>

I need the List to only display the scores of the student.

Something like:

<s:开发者_如何学GoList dataprovider="arrColl[Student A]"/>

or:

<s:List dataprovider="arrColl.Student A."/>


The problem is that the list control wont pick up this "34,65,36,87,12" variable and turn it into a IList List.

I figured it out, I first have to do this: studentAArray = new ArrayCollection(arrColl.score.split(",")); Then use studentAArray as the List dataprovider.


Don't do anything with the list to make this happen. You want to apply a filter to the ArrayCollection. The list will immediately pick up the filter, and remove invalid items from the view.

Set the dataProvider like this:

<s:List dataprovider="arrColl"/>

Then create a filterFunction, something like this:

public function StudentAFilter(item:Object):void{
  if(item['label'] = "Student A"){
   return true;
  }
  return false;
}

And somewhere in your code, do something like this:

arrColl.filterFunction = StudentAFilter;
arrColl.refresh()

The code above is often related to a button click or the change handler of a drop down list; depending how you want the user to filter the data.

0

精彩评论

暂无评论...
验证码 换一张
取 消