举报投诉联系我们 手机版 热门标签 名动网
您的位置:名动网 > flex数据绑定将无法检测对的指定 Flex 数据绑定

flex数据绑定将无法检测对的指定 Flex 数据绑定

2023-05-06 11:20 Flex教程

flex数据绑定将无法检测对的指定 Flex 数据绑定

flex数据绑定将无法检测对的指定 Flex 数据绑定

flex数据绑定将无法检测对的指定

什么是数据绑定?

数据绑定是一个对象的数据绑定到另一个对象的过程。 数据绑定需要源属性,目标属性和指示何时从源到目标复制数据的触发事件。

Flex提供了三种方式来执行数据绑定

  • MXML脚本中的大括号语法({})

  • < fx:binding> 标签

  • ActionScript中的BindingUtils

数据绑定 - 在MXML中使用花括号

以下示例演示使用大括号指定源到目标的数据绑定。

<s:TextInput id="txtInput1"/>
<s:TextInput id="txtInput2" text = "{txtInput1.text}"/>

数据绑定 - 使用< fx:Binding> 标签

以下示例演示使用< fx:Binding> 标记以指定源到目标的数据绑定。

<fx:Binding source="txtInput1.text" destination="txtInput2.text" />
<s:TextInput id="txtInput1"/>
<s:TextInput id="txtInput2"/>

数据绑定 - 在ActionScript中使用BindingUtils

以下示例演示使用BindingUtils指定源到目标的数据绑定。

<fx:Script>
   <![CDATA[
      import mx.binding.utils.BindingUtils;
      import mx.events.FlexEvent;

      protected function txtInput2_preinitializeHandler(event:FlexEvent):void
      {
         BindingUtils.bindProperty(txtInput2,"text",txtInput1, "text");
      }      
]]>
</fx:Script>
<s:TextInput id="txtInput1"/>
<s:TextInput id="txtInput2" 
preinitialize="txtInput2_preinitializeHandler(event)"/>

Flex数据绑定示例

让我们按照以下步骤在Flex应用程序中通过创建测试应用程序来查看操作中的换肤:

描述
1 Flex - 创建应用程序章节中所述,在包 com.tutorialspoint.client 下创建名为 HelloWorld 的项目。
2修改 HelloWorld.mxml ,如下所述。 保持文件的其余部分不变。
3编译并运行应用程序,以确保业务逻辑按照要求工作。

以下是修改的 HelloWorld.mxml 文件 src / com / tutorialspoint / client / HelloWorld.mxml 的内容。

<?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%" minWidth="500" minHeight="500"
   >
   <fx:Style source="/com/tutorialspoint/client/Style.css"/>
   <fx:Script>
   <![CDATA[
      import mx.binding.utils.BindingUtils;   
      import mx.events.FlexEvent;

      protected function txtInput6_preinitializeHandler(event:FlexEvent):void
      {
         BindingUtils.bindProperty(txtInput6,"text",txtInput5, "text");
      }
      ]]>
   </fx:Script>
   <fx:Binding source="txtInput3.text" destination="txtInput4.text" />
   <s:BorderContainer width="500" height="550" id="mainContainer" 
   styleName="container">
      <s:VGroup width="100%" height="100%" gap="50" horizontalAlign="center" 
      verticalAlign="middle">
         <s:Label id="lblHeader" text="Data Binding Demonstration"
         fontSize="40" color="0x777777" styleName="heading"/>
         <s:Panel title="Example #1 (Using Curly Braces,{})" width="400" 
         height="100" >
            <s:layout>
               <s:VerticalLayout paddingTop="10" paddingLeft="10"/>
            </s:layout>
            <s:HGroup >
               <s:Label text = "Type here: " width="100" paddingTop="6"/>
               <s:TextInput id="txtInput1"/>	
            </s:HGroup>
            <s:HGroup >
               <s:Label text = "Copied text: " width="100" paddingTop="6"/>
               <s:TextInput id="txtInput2" text = "{txtInput1.text}"/>
            </s:HGroup>						
         </s:Panel>
         <s:Panel title="Example #2 (Using &lt;fx:Binding&gt;)" width="400" 
         height="100" >
            <s:layout>
               <s:VerticalLayout paddingTop="10" paddingLeft="10"/>
            </s:layout>
            <s:HGroup >
               <s:Label text = "Type here: " width="100" paddingTop="6"/>
               <s:TextInput id="txtInput3"/>	
            </s:HGroup>
            <s:HGroup >
               <s:Label text = "Copied text: " width="100" paddingTop="6"/>
               <s:Label id="txtInput4"/>
            </s:HGroup>						
         </s:Panel>
         <s:Panel title="Example #3 (Using BindingUtils)" width="400" 
            height="100" > <s:layout>
               <s:VerticalLayout paddingTop="10" paddingLeft="10"/>
            </s:layout>
            <s:HGroup >
               <s:Label text = "Type here: " width="100" paddingTop="6"/>
               <s:TextInput id="txtInput5"/>	
            </s:HGroup>
            <s:HGroup >
               <s:Label text = "Copied text: " width="100" paddingTop="6"/>
               <s:TextInput enabled="false" id="txtInput6" 
               preinitialize="txtInput6_preinitializeHandler(event)"/>
            </s:HGroup>						
         </s:Panel>
      </s:VGroup>	 
   </s:BorderContainer>	
</s:Application>

准备好所有更改后,让我们以正常模式编译和运行应用程序,就像在 Flex - 创建应用程序中一样 章节。
如果一切顺利,您的应用程序,这将产生以下结果:[在线试用]

Flex Data Binding
阅读全文
以上是名动网为你收集整理的flex数据绑定将无法检测对的指定 Flex 数据绑定全部内容。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
相关文章
  • flex service Flex RPC服务

    flex service Flex RPC服务

    2023-06-19 Flex教程

    Flex提供RPC服务以向客户端提供服务器端数据。 Flex对服务器端数据提供了相当大的控制。使用Flex RPC服务,我们可以定义要在服务...

  • flex如何使用 Flex 快速指南

    flex如何使用 Flex 快速指南

    2023-05-07 Flex教程

    Flex- 概述什么是Flex?Flex是一个强大的开源应用程序框架,允许使用相同的编程模型,工具和代码库构建针对浏览器,移动设备和桌...

  • maven中的profile作用 Maven 中的 profile

    maven中的profile作用 Maven 中的 profile

    2023-05-21

    Maven 中有一个概念叫做:​profile​,它的诞生主要是为了解决不同环境所需的不同变量、配置等问题。有了 ​profile​,可以根...

  • idea如何使用svn提交代码 IDEA 如何使用SVN

    idea如何使用svn提交代码 IDEA 如何使用SVN

    2023-06-12

    SVN 的这个窗口有的 IntelliJ IDEA 上叫 ​Changes​,有的叫​ Version Control​,具体是什么原因引起这样的差异,我暂时还不...

  • eclipse项目结构显示 Eclipse 项目结构

    eclipse项目结构显示 Eclipse 项目结构

    2023-05-23

    Eclipse 项目结构如上图 Gif 演示,在 Eclipse 下,一般中小项目的项目结构基本都是这种模式的,所以我们这里也通过网上一个开源...

© 2024 名动网 mdwl.vip 版权所有 联系我们