I have a control which contains many child elements (about 1000), and I ne开发者_StackOverflow中文版ed to sort them.
Now I doing that like this:
_elements.sortOn(...);
for (var i: int = 0; i < _elements.length; i++) {
setItemIndex(_childItems[_elements[i].id], i);
}
- _childElement - object that contains UI-child elements, which i need to sort (key of the dictionary is an identifier from data-object
- _elements - array contains data-objects
But this is too slow! How to reorder the childs by my criteria as fast as possible?
I don't have enough info to be sure my answer is correct but... if "_elements" is an arraycollection and it's bound to the control as dataprovider
somethink like < ns:mycontrol dataProvider="{_elements}"/>
each time you change "_elements" the binding makes the control parse and render the data in the dataprovider, so, for a list 1000+ long it's going to be painful.
in this case I'd storethe _elements array (the data of the array collection) in a tmp variable and replace it with a new blank array. then do all your sorting stuff on the tmp and set it back again as the _elements data. by doing this you're just forcing parsing and rendering twice...not 1000+ times :)
my 2 cents, ciao
精彩评论