How can I hide a list component when it contains no items?
-
02-10-2019 - |
Question
I have a List of items which is based on the contents of the "category" that a user selects
When the user changes selection, I change the dataProvider
of the list be be the contents of the current category.
Sometimes the list contains items, sometimes it does not
Is there a way of hiding the list when it has no items?
I know that I could do this when setting the dataProvider
, but it seems like there should be an event or something else that I could be using.
Solution
You could try
visible="{myList.dataProvider.length>0}"
includeInLayout="{myList.dataProvider.length>0}"
where "myList" is the id of your List component.
OTHER TIPS
My first solution to this was to override set dataProvider:
override public function set dataProvider(value:IList):void {
super.dataProvider = value;
this.setVisible(value.length > 0);
}
This did work, however Robusto's solution works also and is preferable IMO.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow