Flex数据绑定陷阱:常见的误用和错误(九)

作者:medcl   类型:编译   来源:9RIA.com天地会

  

第八条

第九条

Binding a class and its properties
绑定一个类又绑定它的属性

Another common mistake is to set a class to be bindable and then make each property in the class bindable as well; for example:

另一个常见的错误就是给一个类设置绑定标签后,给类的每个属性也设置标签;例如:

package
{
   [Bindable]
   public class CustomerVO
   {
      [Bindable]
      public var customerID:int;                             
      public function CustomerVO(customerID:int)
      {
         this.customerID = customerID;
      }
   }
}

The [Bindable] tag is not needed for the CustomerID property because the class is already marked as bindable,
which makes every property in the class bindable.  
This creates compile time warnings (see Figure 7) and writing the extra code wastes time.
Unless you specify an Event name the tag is redundant and should be removed.

类的自定义属性并不需要[Bindable]绑定标签,因为类已经进行了绑定,在类绑定时会将每个属性进行绑定。
这种写法会造成编译时警告(见图7),写额外的代码浪费时间。
除非你特别指定事件名,否则这个标签是多余的,可以被移除的。

Compile time warning for a redundant [Bindable] tag
多余的[Bindable]绑定标签引起的编译时警告



Figure 7. Compile time warning for a redundant [Bindable] tag
图7.多余的[Bindable]绑定标签引起的编译时警告

在线投稿和咨询,联系闪吧编辑    责任编辑:silvia    时间:2010年7月28日
  • 最近更新