显示ItemRenderer的数据属性

时间:2013-04-01 18:19:47

标签: flex flash-builder

我有这个ItemRenderer

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx"
                autoDrawBackground="false">

    <s:HGroup verticalAlign="middle">
        <s:Button label="{data.Nome} ({data.Rating})" width="150" height="35"/>
        <s:Button label="{data.Estado}" width="150" height="30"/>
    </s:HGroup>

</s:ItemRenderer>

我希望在键入data时看到.对象的属性,因为它是自定义对象。我怎么能看到他们?

data被认为是User类对象。

2 个答案:

答案 0 :(得分:1)

试试这个

<fx:Script>
  <![CDATA[
  import yourPackage.User;

  [Bindable]
  private var user:User;

  override public function set data(value:Object):void{
    super.data = value;
    user = data as User;
  }
  ]]>
</fx:Script>
<s:HGroup verticalAlign="middle">
  <s:Button label="{user.Nome} ({user.Rating})" width="150" height="35"/>
  <s:Button label="{user.Estado}" width="150" height="30"/>
</s:HGroup>

答案 1 :(得分:0)

要么ЮрийБорыс说,要么你也可以将数据投射为用户:

<s:Button label="{User(data).Nome} ({User(data).Rating})" width="150" height="35"/>

HIH