例: 名前、標準、年齢などを含む配列コレクションがあります。標準の「x」にいた学生の数が必要です。フレックス ArrayCollection でループなしでこれがどのように可能になるか。
1559 次
1 に答える
0
以下のコードが役立つ場合があります。-ArrayCollectionにfilterFunctionを使用できます。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:local="*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var filterValue:String = "X";
private var myArrayCollection:ArrayCollection = new ArrayCollection(
[{label:"I", data:"first std"},
{label:"II", data:"Second std"},
{label:"III", data:"Third std"},
{label:"V", data:"Fifth std"},
{label:"VI", data:"Sixth std"},
{label:"IX", data:"Ninth std 1"},
{label:"X", data:"Tenth std 1"},
{label:"IX", data:"Ninth std 2"},
{label:"X", data:"Tenth std 2"},
{label:"X", data:"Tenth std 3"}]
);
private function getLengthOfArrayCollection():void
{
myArrayCollection.filterFunction = filterFunctionHandler;
myArrayCollection.refresh();
trace(myArrayCollection.length+" --")
}
private function filterFunctionHandler(item:Object):Boolean
{
var value:Boolean = false;
if(item.label == filterValue)
{
value = true;
}
return value;
}
]]>
</fx:Script>
<s:layout>
<s:HorizontalLayout />
</s:layout>
<s:Button label="Click for Filter" click="getLengthOfArrayCollection()" skinClass="MyButtonSkinClass"/>
</s:Application>
于 2012-11-27T10:55:03.003 に答える