我有一個自定義ItemRenderer的TileList,每個項目顯示一個圖像,它從它從dataProvider接收的數據中提取。奇怪的是,我不知道爲什麼有些項目顯示的圖像不在它們的數據塊中,而是在另一項數據中。如果我從自己的數據中提取圖片url,我不知道如何從另一個項目獲取圖片url。我使用工具提示來顯示圖片網址和項目數據,並驗證該網址不在其數據中。Flex:ListItem從列表中的其他項目中提取數據?
這裏是臨時XML我使用:
<data>
<bs item_id="1">
<variation price="300" month="JAN" stone="Garnet" image="<?=$img_dir?>jan.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="400" month="FEB" stone="Garnet" image="<?=$img_dir?>feb.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="550" month="MAR" stone="Garnet" image="<?=$img_dir?>march.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="625" month="APR" stone="Garnet" image="<?=$img_dir?>april.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
</bs>
<bs item_id="2">
<variation price="300" month="JAN" stone="Garnet" image="<?=$img_dir?>jan.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="400" month="FEB" stone="Garnet" image="<?=$img_dir?>feb.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="550" month="MAR" stone="Garnet" image="<?=$img_dir?>march.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="625" month="APR" stone="Garnet" image="<?=$img_dir?>april.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
</bs>
<bs item_id="3">
<variation price="300" month="JAN" stone="Garnet" image="<?=$img_dir?>jan.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="400" month="FEB" stone="Garnet" image="<?=$img_dir?>feb.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="550" month="MAR" stone="Garnet" image="<?=$img_dir?>march.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="625" month="APR" stone="Garnet" image="<?=$img_dir?>april.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
</bs>
<bs item_id="4">
<variation price="300" month="JAN" stone="Garnet" image="<?=$img_dir?>PE105-BT.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="400" month="FEB" stone="Garnet" image="<?=$img_dir?>PE105-EM.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="550" month="MAR" stone="Garnet" image="<?=$img_dir?>PE105-OP.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
<variation price="625" month="APR" stone="Garnet" image="<?=$img_dir?>PE105.png" style="xsdfcSD" gold_color="Yellow" gold_carat="10"/>
</bs>
</data>
每個項目得到了< BS>塊。 (4項)
這裏是從ItemRender的代碼:
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="150" height="150" xmlns:local="*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var _randomIndex:uint;
private var _indexSet:Boolean;
private function getRandomImage():String
{
if (!_indexSet)
{
var maxIndex:uint = data.children().length();
_randomIndex = Math.floor(Math.random()*maxIndex);
_indexSet = true;
}
return data.children()[_randomIndex][email protected];
}
]]>
</mx:Script>
<local:LoadingImage id="tn" toolTip="{tn.source+'\n\n'+data}" source="{getRandomImage()}" width="150" height="150"/>
</mx:Canvas>
的第二和第三被示出僅在第四塊的圖像。
有沒有人看到我沒有看到的東西?
謝謝!
原因是未檢測到綁定更改。參見: http://stackoverflow.com/questions/445313/can-i-bind-a-flex-component-property-toa-a-function – an0nym0usc0ward 2009-11-07 00:43:34