随笔-75  评论-193  文章-5  trackbacks-0
P984
Data binding requires a source property, a destination property, and a triggering event that
indicates when to copy the data from the source to the destination.

数据绑定需要一个源,一个目标和需要从源拷贝数据到目的一个触发事件。

注意:这句话解释了数据绑定的本质。也引出了下面的一段话。

You can use all properties of a component as the destination of a data binding expression.
However, to use a property as the source of a data binding expression,the component must be
implemented to support data binding, which means that the component dispatches an event
when the value of the property changes to trigger the binding
.
For more information on
creating component properties that can be used as the source of a data binding expression, see
“Bindable metadata tag” in Creating and Extending Flex 2 Components.

上面这段话的关键含义在于有下划线的这一段: 控件必须支持数据绑定,这意味着当属性改变时控件必须发送一个事件来触发数据绑定的操作。

In addition to properties, you can use ActionScript functions as the source of binding
expressions. You usually do this when using a bindable property as an argument of a function.
When the property changes, the function executes, and the result is used in the binding
destination.

对于实行,可以使用ActionScript的函数做为绑定表达式的源。通常可以使用一个绑定的属性做为函数的参数,这样当属性变化时,函数将会执行,结果就会被绑定的目的使用。

注:对上面一段话有了初步的理解,不过最好能有一个例子说明,可惜还没看到:(

You can also use a property of type Function as a binding source or destination. A property of
type Function is a variable that holds a reference to a function.

注:这也是一个说明函数与数据绑定相关的使用方法。
下面终于就要讲到数据绑定的具体使用方法了。

Binding data with curly braces

举例如下:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<!-- Data model stores registration data that user enters. -->
<mx:Model id="reg">
   <registration>
      <name>{name.text}</name>
      <email>{email.text}</email>
      <phone>{phone.text}</phone>
      <zip>{zip.text}</zip>
      <ssn>{ssn.text}</ssn>
   </registration>
</mx:Model>
<!-- Form contains user input controls. -->
<mx:Form>
   <mx:FormItem label="Name" required="true">
      <mx:TextInput id="name" width="200"/>
   </mx:FormItem>
   <mx:FormItem label="Email" required="true">
      <mx:TextInput id="email" width="200"/>
   </mx:FormItem>
   <mx:FormItem label="Phone" required="true">
      <mx:TextInput id="phone" width="200"/>
   </mx:FormItem>
   <mx:FormItem label="Zip" required="true">
      <mx:TextInput id="zip" width="60"/>
   </mx:FormItem>
   <mx:FormItem label="Social Security" required="true">
      <mx:TextInput id="ssn" width="200"/>
   </mx:FormItem>
   ...
</mx:Form>
</mx:Application>

上面的例子很清楚的说明了使用{}做为数据绑定的用法。不过在上面的例子中使用到了DataModel,关于Data Models请参见 Chapter 38, “Storing Data,” on page 1001。
posted on 2006-11-01 23:06 The Matrix 阅读(315) 评论(0)  编辑  收藏 所属分类: Flex2

只有注册用户登录后才能发表评论。


网站导航: