0

我有一个对象的 ArrayCollection。我将此数组作为数据提供者传递给水平列表,并且我正在使用自定义 itemRenderer。

执行应用程序时,显示水平列表

[object CustomClass][object CustomClass][object CustomClass][object CustomClass]

我尝试在 itemrenderer 中强制转换每个对象,如下所示:

<mx:Label text="{(data as CustomClass).label1}"/>

但它不工作...

感谢您的任何帮助,您可以提供。问候,

BS_C3


编辑 - 2010 年 3 月 9 日

让我们再看一些代码 =)

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Component id="Item">
        <mx:VBox width="180">
            <mx:HBox width="100%">
                <mx:Spacer width="100%"/>
                <mx:Button label="x"/>
            </mx:HBox>
            <mx:Image id="thumbnail"/>
            <mx:Label width="100%" horizontalCenter="0" text="Collection"/>
            <mx:HBox width="100%">
                <mx:Label width="100" text="GIA"/>
                <mx:Label text="{data.charg_st}"/>
            </mx:HBox>
            <mx:HBox width="100%">
                <mx:Label width="100" text="Finger Size"/>
                <mx:Label text="xxxxxx"/>
            </mx:HBox>
            <mx:HBox width="100%">
                <mx:Label width="100" text="Carat"/>
                <mx:Label text="{data.carats}"/>
            </mx:HBox>
            <mx:HBox width="100%">
                <mx:Label width="100" text="Color"/>
                <mx:Label text="{data.color}"/>
            </mx:HBox>
            <mx:HBox width="100%">
                <mx:Label width="100" text="Clarity"/>
                <mx:Label text="{data.clarity}"/>
            </mx:HBox>
            <mx:HBox width="100%">
                <mx:Label width="100" text="Shop"/>
                <mx:Label text="{data.lgort_fp}"/>
            </mx:HBox>
            <mx:HBox width="100%">
                <mx:Label width="100" text="Resizing"/>
                <mx:Label text="{data.resizing}"/>
            </mx:HBox>
            <mx:HBox width="100%">
                <mx:Label width="100" text="Price Excl. VAT"/>
                <mx:Label text="{data.net_price_fp}"/>
            </mx:HBox>
        </mx:VBox>
    </mx:Component>


    <mx:HorizontalList
        dataProvider="{GlobalData.instance.tray}" 
        columnCount="4"
        rowCount="1"
        horizontalScrollPolicy="off"
        itemRenderer="{Item}"
    />
</mx:Canvas>

仅供参考,horizo​​nalList 数据提供者是对象的 ArrayCollection。

现在,水平列表正在显示空项目......具有正确的宽度...... arraycollection 不为空(我在项目的点击事件上使用警报,并且我确实检索了预期的数据)。

希望这会有所帮助>_<

问候,BS_C3

4

4 回答 4

0

你有没有尝试过

<mx:Label text="{data.label1}"/>

? (label1作为您的对象的属性)

于 2010-03-08T15:25:24.843 回答
0

使用labelField列表中的字段,请参见此处

<mx:List dataProvider="{myDataProvider}" labelField="label1"/>
于 2010-03-08T15:27:50.317 回答
0

尝试将您的自定义类声明为组件中某处的变量。声明类的实例后,Flex 可能会更成功地识别类的属性。

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script>
    <![CDATA[
      private var myClass:CustomClass;
    ]]> 
  </mx:Script>
    <mx:Component id="Item">
        <mx:VBox width="180">
         ...

thelost的代码也正确。你应该可以使用

<mx:Label text="{data.label1}"/>

在您的itemRenderer.

编辑:我确定您已经完成了此操作,但还要仔细检查您是否已将您设置为dataProviderHorizontalList的.[Bindable]CustomClass

于 2010-03-09T16:17:40.550 回答
0

我设法解决了我的问题。

当我去掉itemrenderer的vbox的width属性时,所有的数据都出现在了horizo​​ntalList中。为什么?我不知道为什么,但它似乎将数据定位在水平列表的可见范围之外(嗯??)。

问题是现在一切正常。对于最终代码,您有:

水平列表:

<mx:HorizontalList id="hlist"
    dataProvider="{TrayData.instance.itemsCollection}" 
    columnCount="{TrayData.instance.hlistColumns}"
    rowCount="1"
    itemRenderer="components.TrayItem"
    horizontalScrollPolicy="off"
    horizontalCenter="0" verticalCenter="0"
    borderStyle="none"
    horizontalScrollPosition="{TrayData.instance.hsPosition}"
    />

项目渲染器:

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" >

    <mx:HBox width="100%">
        <mx:Spacer width="100%"/>
        <mx:Button label="x"/>
    </mx:HBox>
    <mx:HBox width="100%">
        <mx:Spacer width="15%"/>
        <mx:VBox width="70%">
            <mx:Image id="thumbnail" horizontalAlign="center"/>
            <mx:Label width="100%" textAlign="center" text="Collection"/>
            <mx:HBox width="100%">
                <mx:VBox id="labelBox" width="100">
                    <mx:Label width="100" text="GIA"/>
                    <mx:Label width="100" text="Finger Size"/>
                    <mx:Label width="100" text="Carat"/>
                    <mx:Label width="100" text="Color"/>
                    <mx:Label width="100" text="Clarity"/>
                    <mx:Label width="100" text="Shop"/>
                    <mx:Label width="100" text="Resizing"/>
                    <mx:Label width="100" text="Price"/>
                </mx:VBox>
                <mx:VBox id="dataBox" width="100%" horizontalAlign="left">
                    <mx:Label text="{data.resizingCode + ' ' + data.charg_st}"/>
                    <mx:Label text="{data.fingerSize}"/>
                    <mx:Label text="{((new Number(data.carats))/100).toString()}"/>
                    <mx:Label text="{data.color}"/>
                    <mx:Label text="{data.clarity}"/>
                    <mx:Label text="{data.lgort_fp}"/>
                    <mx:Label text="{data.net_price_fp}"/>
                </mx:VBox>
            </mx:HBox>
            <mx:Button label="Order" enabled="{data.product_type == 'C'}" width="50%"/>
        </mx:VBox>
        <mx:Spacer width="15%"/>
    </mx:HBox>

</mx:VBox>

问候,BS_C3

于 2010-03-15T13:21:20.163 回答