您的位置:首页 > 其它

Flex 3快速入门: 构建高级用户界面 使用 Repeater 组件

2009-09-07 15:30 721 查看
本文来自:http://www.airia.cn/FLEX_Directory/using_the_repeater/

使用 Repeater 组件(Repeater component)

Repeater 组件用于重复制作一些简单用户界面组件。如按钮控件和其他在窗体容器中通常使用的控件。例如他与我们常见的FOR循环类似。

通常,您控制重复使用数组的动态数据,例如从 Web 服务返回的 Array 对象,您可以使用静态数组模拟简单的循环。

你可以使用 <mx:Repeater> 标签声明一个 Repeater 组建 ,在运行时中重复一个或多个用户界面组件。重复的组件可以是控件或容器。使用 Repeater 组件需要便于运行时特定值的数据绑定。

通常你可以将<mx:Repeater> 标签用于能使用控制或容器标签的任何地方。若要重复用户界面组件,你只需将他们放置在<mx:Repeater>内即可。除了<mx:Application>容器标签以外,所有源于UI组建类的组建都可以被重复。

你还可以在MXML里使用多个<mx:Repeater>标签和嵌套<mx:Repeater>标签。虽然Repeater组件看起来是您的代码中的容器,但是他们只是不具备自动布局功能的容器。

例如,以下代码段创建多个 RadioButton 控件根据产品的 ArrayCollection,每个包含名称属性。 容器的布局属性设置为"水平"使 RadioButton 控件显示排列在一行中。

<mx:Panel layout="horizontal">

<mx:Repeater id="productsRepeater" dataProvider="{productsAC}">
<mx:RadioButton id="buttonsArray"
label="{productsRepeater.currentItem.name}"

data="{productsRepeater.currentItem}"
/>
</mx:Repeater>
</mx:Panel>

使用 Repeater 模拟FOR循环

最简单的重复结构可以创建Repeater 组件是静态的循环,设置执行的次数。

Repeater 组件在下面的示例模拟一个简单的循环,执行四次打印简单的一行文本,每次递增计数器。

代码

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
viewSourceURL="src/RepeaterStatic/index.html"
width="275" height="200"

>
<mx:Script>
<![CDATA[
[Bindable]
public var myArray:Array=[1,2,3,4];
]]>

</mx:Script>

<mx:Panel
title="Repeater: emulating a for loop"
paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"

>

<mx:Repeater id="myRep" dataProvider="{myArray}">
<mx:Label
id="myLabel"
text="This is loop #{myRep.currentIndex}"

/>
</mx:Repeater>

</mx:Panel>
</mx:Application>

提示:重构数组声明

public var myArray:Array=[,,,,]; // The actual values do not matter in this use-case
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: