2010-05-09 3 views
2

작은 사진 갤러리에서 작업 중입니다. XML 파일을 만들고 itemrenderer를 사용하여 List 컨트롤에 연결하려고합니다. 그러나 파일을 저장할 때 정의되지 않은 속성 "데이터"오류에 액세스했습니다. 나는 우리가 데이터 객체의 현재 행을 참조하기 위해 "데이터"를 사용한다고 생각했다. 여기 내 코드가 있습니다 ... 그리고 많은 감사합니다!플렉스 목록 제어 항목 다시 발행자

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
<fx:Declarations> 
    <fx:Model id="pictureXML" source="data/pictures.xml"/> 
    <s:ArrayList id="pictureArray" source="{pictureXML.picture}"/> 
</fx:Declarations> 



<s:List id="pictureGrid" dataProvider="{pictureArray}" 
    horizontalCenter="0" top="20"> 
    <s:itemRenderer> 
    <fx:Component> 
    <s:HGroup> 
    <mx:Image source="images/big/{data.source}" /> // where the error happen 
    <s:Label text="{data.caption}"/> // where the error happen 
    </s:HGroup> 

    </fx:Component> 
    </s:itemRenderer> 
</s:List> 


</s:Application> 

내 XML

<?xml version="1.0"?> 
<album> 
    <picture> 
    <source>city1.jpg </source> 
    <caption>City View 1</caption> 
    </picture> 
    <picture> 
    <source>city2.jpg </source> 
    <caption>City View 2</caption> 
    </picture> 
    <picture> 
    <source>city3.jpg </source> 
    <caption>City View 3</caption> 
    </picture> 
    <picture> 
    <source>city4.jpg </source> 
    <caption>City View 4</caption> 
    </picture> 
    <picture> 
    <source>city5.jpg </source> 
    <caption>City View 5</caption> 
    </picture> 
    <picture> 
    <source>city6.jpg </source> 
    <caption>City View 6</caption> 
    </picture> 
    <picture> 
    <source>city7.jpg </source> 
    <caption>City View 7</caption> 
    </picture> 
    <picture> 
    <source>city8.jpg </source> 
    <caption>City View 8</caption> 
    </picture> 
    <picture> 
    <source>city9.jpg </source> 
    <caption>City View 9</caption> 
    </picture> 
    <picture> 
    <source>city10.jpg </source> 
    <caption>City View 10</caption> 
    </picture> 
</album> 

내가 어떤 도움 주셔서 감사합니다!

+0

오류는 mx : Image 행 또는 mx : Image와 s : Label 모두에서만 발생합니까? – NKijak

답변

3
<s:List id="pictureGrid" dataProvider="{pictureArray}" 
    horizontalCenter="0" top="20"> 
    <s:itemRenderer> 
    <fx:Component> 
     <s:ItemRenderer> 
    <s:HGroup> 
    <mx:Image source="images/big/{data.source}" /> // where the error happen 
    <s:Label text="{data.caption}"/> // where the error happen 
    </s:HGroup> 
    </s:ItemRenderer> 
    </fx:Component> 
    </s:itemRenderer> 
</s:List> 

시험 사용해보십시오! 그것은 작동 할 것이다

1

액세스하려고하는 데이터 속성이 인라인 itemRenderer에 있기 때문에 범위를 벗어난 것 같습니다. ItemRenderer를 인라인 컴포넌트로 사용하는 대신 자체 컴포넌트로 추상화 해보십시오.

또한 각 항목의 데이터 속성에 대한 액세스 권한을 얻을 수있는 인라인 (in-line)의 itemRenderer에 도달 할 수 있습니다 만,이 청소기입니다 .... 내가 자신의 구성 요소로 IR을 분리 한

및 모든 것 잘 ...

<!-- YOUR LIST --> 
<s:List id="pictureGrid" dataProvider="{pictureArray}" 
       horizontalCenter="0" top="20" 
       itemRenderer="TestRenderer"/> // reference new IR class here 

<!-- NEW ITEMRENDERER CLASS --> 
<?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="true"> 

     <s:HGroup> 
      <mx:Image source="images/big/{data.source}" /> 
      <s:Label text="{data.caption}"/> 
     </s:HGroup> 

</s:ItemRenderer> 
0

는 문제가 해결되지 않은 경우 다음 말해이 하나

override public function set data(value:Object):void 
    { 
       super.data = value; 
       if (data == null) 
        return; 

       irImage.source = data.path; 
          irText.text = data.caption 

    } 


<s:HGroup> 
      <mx:Image id="irImage" /> 
      <s:Label id="irText"text="{data.caption}"/> 
</s:HGroup> 

을 시도합니다.