In Flex, every component is identified by its unique id property. Therefore, in your own data, it's better not to use id as a property.
In the following function, imageList is a List control, the id of each item is not the id of its data provider.
The original data is "<Image source="..." imageId="..."/>"
<mx:List width="120" height="100%" id="imageList" dataProvider="{images}" itemRenderer="ImageItem" change="onChange()" dropShadowEnabled="true" borderStyle="solid" borderThickness="2"></mx:List>
.......
public function onChange():void { //Alert.show(imageList.selectedItem.id.toString()); imgChara.source=imageList.selectedItem.source; imageId=imageList.selectedItem.imageId; }
The following code does not work correctly!
if the original data is "<Image source="..." id="..."/>"
public function onChange():void { //Alert.show(imageList.selectedItem.id.toString()); imgChara.source=imageList.selectedItem.source; imageId=imageList.selectedItem.id; }
本文探讨了在InFlex框架中正确使用组件ID的方法。强调了避免将数据ID作为组件ID的重要性,并通过示例展示了如何在List控件中正确获取项目源与ID,确保应用程序的稳定运行。
1774

被折叠的 条评论
为什么被折叠?



