Emptying a View
Hi
Is there any way to empty the contents of a view - without knowing the children views objects names?
Caspar
6 Answers
-
Accepted Answer
for( var c in the_view.children ) { the_view.remove( the_view.children[c] ); }
not tested.
-
Tama's code didn't work quite right for me… but this did (after some aggravating debugging):
for(var c=the_view.children.length-1;c >= 0; c-- ) { the_view.remove( the_view.children[c] ); }
-
Dan Tomas's answer above does not work. In the second round the length of the array will be lower that when you started the loop. Therefore eventually you will exceed the array boundary.
try this:
while (the_view.children !== null){ the_view.remove(the_view.children[0]); };
-
Neither works for me.
-
There's this method that you can use:
view.removeAllChildren( );
I have tested it and it's working for me.
-
Better:
while(navigationView.children.length){ navigationView.remove(navigationView.children[0]); };