简体   繁体   English

在Flash Builder中,如何制作 <s:List> dataprovider =“数组的某些部分”?

[英]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.

相关问题 如何将XML加载到MXML Flash Builder 4中的List组件中? - How do I load XML into a List component in MXML Flash Builder 4? 如何使用本地 XML 文件作为 Flex 4.5 中 Spark 列表控件的 DataProvider? - How do I use a local XML file as a DataProvider for a Spark List control in Flex 4.5? 如何使Flash等到加载XML以使函数可用于从另一个类调用? - How do I get Flash to wait until XML is loaded to make a function available for calling from another class? 如何为Sitecore 8.2.5配置数据提供程序,以便Sitecore内核调用其构造函数? - How do I have to configure a dataprovider for Sitecore 8.2.5 so its constructor is called by the Sitecore Kernel? 如何在ID列表中找到重复的ID - How do I find duplicated id's in a list of ID's 如何使用 Android XML 制作裁剪部分图层列表 - How can i make clipped part layer-list using Android XML 如何使用Flash AS3中XML对象中的特定元素创建DataProvider - How to create a DataProvider using specific elements from an XML object in Flash AS3 按下按钮后如何使按钮变色? - How do I make the button change color when it's pressed? 如何在XML文件中将列表打印为按钮? (Android) - How do I make a list be printed as buttons in the xml file? (Android) 从XML在Flash Builder 4.5中的火花列表中显示图像 - Display Image in a Spark List in Flash Builder 4.5 from XML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM