How can I remove / clear items out of a list control in Flex?
Solution 1
Perhaps...
list.dataProvider = new Array();
Solution 2
Setting the dataProvider
to a new Array
object will throw an error:
Implicit coercion of a value of type Array to an unrelated type fl.data:DataProvider.
Instead, you should use the removeAll()
method provided by DataProvider:
list.dataProvider.removeAll();
This triggers a REMOVE_ALL event in the DataProvider which, in turn, will update your list.
mmattax
Senior Software Developer & Devops @ Formstack BS Computer Science, Purdue University Twitter: mmattax
Updated on June 04, 2022Comments
-
mmattax about 2 years
I have a list control in Flex that has been data bound to an e4x xml object from an HTTPService.
I would now like to have a button that clears the list, how can I do this?
I have tried:
list.dataProvider = null;
which does not seem to work, I have also tried:
list.dataProvider = {};
which clears the items but leaves [object,object] as the first item in the list...
-
merv over 12 years-1 - Questioner is asking about Flex, whereas your answer only pertains to components inheriting from fl.controls.SelectableList. The corresponding Flex components' property
dataProvider
is of type Object, and doesn't have such casting problems as you ran into.