2

私は小さなフォトギャラリーに取り組んでいます。xmlファイルを作成し、itemrendererを使用してリストコントロールにリンクしようとしています。しかし、ファイルを保存しようとすると、未定義のプロパティ「データ」エラーにアクセスできました。データオブジェクトの現在の行を参照するために「data」を使用することになっていると思いました。これが私のコードです...そしてどうもありがとう!

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

私はどんな助けにも感謝します!!!

4

3 に答える 3

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>

これを試して!それはうまくいくだろう

于 2011-07-31T05:32:26.000 に答える
1

アクセスしようとしているデータプロパティは、インラインitemRenderer内にあるため、範囲外だと思います。ItemRendererをインラインコンポーネントとして実行するのではなく、独自のコンポーネントに抽象化してみてください。

インラインの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>
于 2011-02-07T21:36:52.790 に答える
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> 

これがうまくいかない場合は教えてください。

于 2011-05-05T09:45:23.850 に答える