加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex4 Spark组件数据驱动简单示例

发布时间:2020-12-15 03:46:36 所属栏目:百科 来源:网络整理
导读:此处通过一个示例来使用List、DropDownList、ButtonBar三个数据驱动组件。 ?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/f

此处通过一个示例来使用List、DropDownList、ButtonBar三个数据驱动组件。

<?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"
  width="100%" height="100%">
<fx:Script><![CDATA[
  import spark.events.IndexChangeEvent;
  import mx.collections.ArrayCollection;

  [Bindable]
  private var _jobTitle:ArrayCollection =
    new ArrayCollection(["CEO","CTO","CIO"]);
  
  [Bindable]
  private var _coffees:ArrayCollection = new ArrayCollection([
    "mocha","macchiato","cappuccino","latte"]);

  [Bindable]
  private var _lunches:ArrayCollection = new ArrayCollection(["Subway","Yoshinoya","Mcdonalds"]);
  
  [Bindable]
  private var _Choice:String = "CEO";
  
  [Bindable]
  private var _coffeeChoice:String = "macchiato";
  
  [Bindable]
  private var _lunchChoice:String = "Yoshinoya";
   
  //此函数用于相应“咖啡选择变化”
  private function coffeeChanged(event:IndexChangeEvent):void {
    if (event.newIndex == -1) return;
    _coffeeChoice = _coffees.getItemAt(event.newIndex) as String;
  }
]]></fx:Script>
  <s:layout>
    <s:VerticalLayout paddingLeft="15" paddingTop="15"/>
  </s:layout>
  <s:Label text="Spark 数据驱动 简单示例" fontSize="18"/>
  <s:List id="list" dataProvider="{_jobTitle}"
    selectedItem="{_Choice}"
	  change="_Choice = list.selectedItem;"/>
  <!--DropDownList是List的一个子类,如果在Flex3中,此处也许会选择ComboBox-->
  <s:DropDownList id="ddl" width="120"
    dataProvider="{_coffees}"
    selectedItem="{_coffeeChoice}"
    change="coffeeChanged(event)"/>
  <!--ButtonBar能与视图状态结合进行导航,此示例中可见三个按钮就在一个容器中-->
  <s:ButtonBar id="buttonBar" dataProvider="{_lunches}"
    selectedItem="{_lunchChoice}"
    click="_lunchChoice = buttonBar.selectedItem;"/>      
  <s:Label width="300"
    text="Mr XXX is a {_Choice},he would like to went to Costa for a {_coffeeChoice},and then have lunch in {_lunchChoice}. "/>
</s:Application>
示例较简单,说明写在了注释中。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读