2010-03-08 90 views
0

我有一個ArrayCollection對象。 我將這個數組作爲數據提供者傳遞給horizo​​nallist,並使用自定義的itemRenderer。Flex-Typed ArrayCollection作爲Horizo​​ntallist的數據提供者

在執行應用程序時,Horizo​​ntalList將被顯示

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

我試過在鑄造的itemRenderer每個對象如下:

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

但它不工作...

感謝您提供任何幫助。 問候,

BS_C3


編輯 - 2010

03月09日我們去一些代碼=)

<?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 dataProvider是對象的ArrayCollection。

現在,horizo​​ntallist正在顯示空的項目...以正確的寬度... arraycollection不是空的(我對項目上的click事件使用警報,並且檢索預期的數據)。

希望這將有助於> _ <

問候, BS_C3

+0

您可以添加更多的代碼或一個完整的測試用例? – Patrick 2010-03-09 10:59:35

+0

沒有人有解決方案? 我一直在嘗試不同的解決方案,但它仍然無法正常工作。 itemrenderer中的所有內容都顯示爲「BLANK」。 這就像物品在那裏,但有東西隱藏它。 我已經添加了一個itemClick事件來顯示該項目的數據,它確實顯示... 我也重新創建了arraycollection作爲一個arraycollection的對象......並且它不改變horizo​​ntallist的行爲。仍然得到一個空白項目... 我真不明白> _ < 任何線索? – 2010-03-12 09:58:38

回答

0

我設法解決了我的問題。

當我刪除了itemrenderer的vbox的width屬性時,所有數據都出現在horizo​​ntalList中。 爲什麼?我不知道爲什麼,但它似乎將數據定位在水平分辨者的可見範圍之外(呵呵)。

事情就是現在一切正常。而對於最終的代碼,有你有:

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}" 
    /> 

的ItemRenderer:

<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

0

您是否嘗試過

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

? (label1是你對象的屬性)

+0

嗨! 是的,那是我做的第一件事,也沒有奏效。我得到的東西就像[object Object] [object Object] [object Object] ...鑑於它不起作用,我使用鑄造的「數據」作爲「自定義類」類型的對象。但它也沒有工作...... -_-' – 2010-03-08 23:52:44

+0

有趣的,那麼請確保你的數據類型是「可打印的」。 – thelost 2010-03-09 07:22:09

+0

嗨! 「打印」是什麼意思? – 2010-03-09 14:37:39

0

您的列表中使用labelField場,看到here

<mx:List dataProvider="{myDataProvider}" labelField="label1"/> 
+0

嗨! 感謝您的回答,但您的解決方案不適合我的問題... 我創建的項目渲染器有很多控件,並且我對所有控件都有同樣的問題...(其他標籤,圖像等...) 有沒有其他想法? – 2010-03-08 23:51:03

+0

沒有看到更多的代碼給你設計,沒有更多的想法;) – Patrick 2010-03-09 10:59:02

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訪問類的屬性。

編輯:我相信你已經這樣做了,而且還仔細檢查你已經在你的HorizontalList設置dataProvider[Bindable]聲明你CustomClass的。

相關問題