数据提供程序和集合

本文介绍如何使用ActionScriptArrayCollection定义数据提供程序,并将其与SparkComboBox控制结合使用来展示数据。通过自定义labelToItemFunction,实现数据的灵活展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面的简单示例介绍了控件是如何定义数据提供程序(定义为 ActionScript ArrayCollection)以及使用数据提供程序的:

<!-- Simple example to demonstrate the Spark ComboBox control --> 
<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/halo">

<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;

[Bindable]
public var complexDP:ArrayCollection = new ArrayCollection(
[ {ingredient:"Salmon", category:"Meat"},
{ingredient:"Potato", category:"Starch"},
{ingredient:"Cucumber", category:"Vegetable"},
{ingredient:"Steak", category:"Meat"},
{ingredient:"Rice", category:"Starch"},
{ingredient:"Cumin", category:"Spice"}
]
);

private function myLabelToItemFunction(input:String):*
{
return {ingredient:input, category:"mystery"};
}
]]>
</fx:Script>

<s:Panel title="Spark ComboBox Example" width="75%" height="75%">
<s:layout>
<s:VerticalLayout paddingTop="10" paddingLeft="10"/>
</s:layout>

<!-- Label that displayed current property values -->
<s:Label text="Index : {cb.selectedIndex}
Item : {cb.selectedItem.ingredient}
Type : {cb.selectedItem.category}"/>

<!-- ComboBox with custom labelToItem function -->
<s:ComboBox
id="cb"
dataProvider="{complexDP}"
width="150"
labelToItemFunction="{myLabelToItemFunction}"
selectedIndex="0"
labelField="ingredient"/>
</s:Panel>
</s:Application>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值