开发者

how can we access a component within an itemRenderer from the main mxml?

开发者 https://www.devze.com 2023-01-07 07:42 出处:网络
I have an itemRenderer for a list where I\'m just displaying items and their details respectively. I want to keep the details invisible and have a button,Show Details, in my main mxml file which when

I have an itemRenderer for a list where I'm just displaying items and their details respectively. I want to keep the details invisible and have a button,Show Details, in my main mxml file which when clicked would make the details visible.

So, my problem is in the clickHandler how can I access the details property within the itemRenderer from the main mxml?

Thanks in advance for y开发者_开发百科our help


I would have a Boolean on the main which is what the itemRenderer keys off of. Accessing the itemRenderers of a list is not receommended because they are recycled, and operations cannot be guaranteed.

For an explanation see http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html


There are a few ways to approach this.

One is to use a global Singleton object that contains the "ShowDetails" value. Every itemRenderer can access that object and change it's settings. Cairngorm's ModelLocator is one example of a singleton that is commonly used in this way. I believe swiz has something similar. You could also roll your own if needed.

You could try to extend the List class The List keeps itemRenderers in an array, which I believe is protected. You'll have to extend the List, and make this protected array public. Then you'll be able to access the list of itemRenderers and modify properties on them directly.

However, I'm not sure I would recommend either approach. An itemRenderer really should choose what to display based on the data it is displaying; not some global variable. Can you change the objects in your dataProvider and have the itemRenderer update accordingly? It is a third option; although I'm not sure if it is any better, or worse, than the previous two approaches.


You could have a variable in the DataProvider array called 'show' thats set to false. In the itemrenderer bind the visible property of the details component to data.show.

When the show button is pressed, traverse the dataProvider array, and set the 'show' property to true. This will work

Bish

0

精彩评论

暂无评论...
验证码 换一张
取 消