Flex4.6_單向與雙向數據綁定使用Label與TextInput範例
- <?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">
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <s:layout>
- <s:VerticalLayout paddingLeft="5" paddingTop="5"/>
- </s:layout>
- <s:TextInput id="textInput1" text="{textInput2.text}" x="191" y="174"/>
- <s:TextInput id="textInput2" text="{textInput1.text}" x="191" y="248"/>
- <s:Label x="190" y="341" text="# chars:{textInput1.text.length}"/>
- </s:Application>
每個TextInput組件的text屬性都被綁定使用 ({}語法) 到另一個TextInput 組件的text屬性上。
顯示結果:
另一種做法也是一樣結果,textInput1組件的text 屬性擁有更為神奇的@{}語法,它意味著"把這個屬性雙向綁定"。
- <?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">
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <s:layout>
- <s:VerticalLayout paddingLeft="5" paddingTop="5"/>
- </s:layout>
- <s:TextInput id="textInput1" text="@{textInput2.text}" x="191" y="174"/>
- <s:TextInput id="textInput2" x="191" y="248"/>
- <s:Label x="190" y="341" text="# chars:{textInput1.text.length}"/>
- </s:Application>
顯示結果:
留言
張貼留言