[英]In Flash Builder, how do I make a <s:List> dataprovider=“certain part of an Array”?
I have a List, and I have an ArrayCollection. 我有一个列表,并且有一个ArrayCollection。
The ArrayCollection is something like: ArrayCollection类似于:
<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:List 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. 问题在于列表控件不会选择此“ 34,65,36,87,12”变量并将其转换为IList列表。
I figured it out, I first have to do this: studentAArray = new ArrayCollection(arrColl.score.split(",")); 我想通了,我首先必须这样做:studentAArray = new ArrayCollection(arrColl.score.split(“,”)); Then use studentAArray as the List dataprovider. 然后使用studentAArray作为List数据提供者。
Don't do anything with the list to make this happen. 不要对列表进行任何操作以实现此目的。 You want to apply a filter to the ArrayCollection. 您想要将过滤器应用于ArrayCollection。 The list will immediately pick up the filter, and remove invalid items from the view. 该列表将立即使用过滤器,并从视图中删除无效的项目。
Set the dataProvider like this: 像这样设置dataProvider:
<s:List dataprovider="arrColl"/>
Then create a filterFunction , something like this: 然后创建一个filterFunction ,如下所示:
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. 取决于您希望用户如何过滤数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.