Apache flex Flex-Typed数组集合作为Horizontallist';数据提供者

Apache flex Flex-Typed数组集合作为Horizontallist';数据提供者,apache-flex,dataprovider,arraycollection,typed,Apache Flex,Dataprovider,Arraycollection,Typed,我有一个对象的数组集合。 我将此数组作为数据提供程序传递给horizontallist,并使用自定义itemRenderer 执行应用程序时,将显示水平列表 [object CustomClass][object CustomClass][object CustomClass][object CustomClass] 我已尝试在itemrenderer中强制转换每个对象,如下所示: <mx:Label text="{(data as CustomClass).label1}"/>

我有一个对象的数组集合。 我将此数组作为数据提供程序传递给horizontallist,并使用自定义itemRenderer

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

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

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

但它不起作用

谢谢你能提供的帮助。 问候,

学士学位C3


编辑-2010年3月9日

让我们看更多的代码=)


仅供参考,horizonalList数据提供程序是对象的ArrayCollection

现在,水平列表显示的是空项。。。用正确的宽度。。。 arraycollection不是空的(我正在使用一个关于某个项目的click事件的警报,并且我确实检索到了预期的数据)

希望这会有帮助你试过了吗

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


??(
label1
是对象的属性)

使用列表中的
labelField
字段,请参阅


尝试将自定义类声明为组件中的某个变量。一旦声明了类的实例,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">
         ...

...
他的代码也是正确的。你应该能够使用

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

项目渲染器中访问类的属性


编辑:我确信您已经这样做了,但也再次检查您是否已将
水平列表中的
数据提供程序设置为
[Bindable]
声明您的
自定义类

我已设法解决了我的问题

当我删除itemrenderer的vbox的width属性时,所有数据都出现在horizontalList中。 为什么?我不知道为什么,但它似乎将数据定位在地平线列表可见范围之外的某个位置(嗯??)

问题是现在一切都在运转。对于最终代码,您有:

水平列表:

<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>

问候,,
你好!谢谢你的回答,但你的解决方案不适合我的问题。。。我创建的项目渲染器有很多控件,我对所有控件都有相同的问题。。。(其他标签、图片等)还有其他想法吗?嗨!是的,这是我做的第一件事,但它不起作用。我得到的是类似于[对象对象][对象对象][对象对象对象]。。。考虑到它不起作用,我使用铸造的“数据”作为“自定义类”类型的对象。但它也不起作用…-"有趣,那么请确保您的数据类型是“可打印的”。嗨!“可打印”是什么意思?你能添加更多的代码或完整的测试用例吗?没有人有解决方案吗?我一直在尝试不同的解决方案,但仍然不起作用。itemrenderer中的所有内容都显示为“空白”。好像物品就在那里,但有什么东西藏了起来。我添加了一个itemClick事件来显示项目的数据,它确实显示了。。。我还将arraycollection重新创建为对象的arraycollection。。。它也不会改变水平主义者的行为。仍然得到一个空白项。。。我真的不明白><任何线索??
<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>