2010-03-08 3 views
0

ArrayCollection에 객체가 있습니다. 이 배열을 가로 좌표로 dataprovider로 전달하고 있는데 사용자 정의 itemRenderer를 사용하고 있습니다.Horizontallist의 데이터 제공자로 형식화 된 ArrayCollection

응용 프로그램을 실행하면, horizontallist이

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

나는 다음과 같이 itemRenderer를 각 개체를 캐스팅하려고했습니다 표시됩니다

:

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

을하지만 작동하지 않습니다 ...

제공 할 수있는 도움에 감사드립니다. 편집


BS_C3

감사합니다 -

2010 09 3 월의 좀 더 코드 가자 =)

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

는 참고의 horizonalList의 dataProvider의 객체의 ArrayCollection에 있습니다.

이제 widthallist가 정확한 너비의 빈 항목을 표시하고 있습니다 ... arraycollection이 비어 있지 않습니다 (항목의 click 이벤트에 경고를 사용하고 예상 데이터를 검색합니다).). 이 _> <

감사합니다 도움이 될 것입니다

희망, BS_C3

+0

당신이 더 많은 코드 또는 완전한 테스트 케이스를 추가 할 수 있습니까? – Patrick

+0

아무도 해결책이 없습니까? 나는 여전히 작동하지 않는 다른 솔루션을 계속 시도해 왔습니다. itemrenderer 안에있는 모든 것이 "공백"으로 표시됩니다. 항목과 비슷하지만 뭔가가 숨어 있습니다. 항목의 데이터를 표시하기 위해 itemClick 이벤트를 추가했으며 표시합니다. arraycollection을 객체의 배열 컬렉션으로 다시 만들었습니다 ... 그리고 가로 좌표의 동작을 변경하지 않습니다. 아직도 빈 항목을 받고 ... 정말 이해가 안되네> _ < 단서 ?? –

답변

0

문제를 해결할 수있었습니다.

itemrenderer의 vbox의 width 속성을 제거하면 모든 데이터가 horizontalList에 나타납니다. 왜? 나는 왜 그런지 모르지만 그것은 가로 좌표의 가시 범위 밖의 데이터 위치를 지정하는 것처럼 보입니다 (응?).

모든 것이 지금 작동 중입니다. 그리고 마지막 코드, 거기 당신은 :

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

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

를 시도?

+0

안녕하세요! 예, 제가 한 첫 번째 작업 이었지만 작동하지 않았습니다. 내가 얻을 수있는 것은 [object Object] [object Object] [object Object] ...와 같은 것입니다. 작동하지 않는다면, "custom class"유형의 객체로 형 변환 된 "data"를 사용했습니다. 하지만 그 중 하나가 작동하지 않았다 ... -_- ' –

+0

재미있는 다음 데이터 유형이 "인쇄 가능"인지 확인하십시오. – thelost

+0

안녕하세요. "인쇄 가능"이란 무엇입니까? –

0

는 목록 내에서 labelField 필드를 사용하여 (label1이 객체의 속성 인), here

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

안녕하세요! 답해 주셔서 감사합니다. 그러나 귀하의 솔루션이 제 문제에 부합하지 않습니다 ... 작성한 아이템 렌더러는 많은 컨트롤을 가지고 있으며 모든 컨트롤에 동일한 문제가 있습니다 (다른 레이블, 이미지 등). ...) 다른 아이디어? –

+0

더 많은 코드를 보지 않고도 더 이상 생각할 필요가 없습니다. – Patrick

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 너무 코드가 있습니다. 당신은 당신의 itemRenderer에서 클래스의 속성에 액세스

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

을 사용할 수 있어야합니다.

편집 : 나는 당신이 당신의 CustomClass[Bindable] 선언에 HorizontalListdataProvider을 설정 한 당신이 이런 짓을했는지, 또한 한 번 확인 해요.