Quelqu'un peut-il me conduire à SHIFT un élément dans un ArrayCollection en flex?Déplacer des éléments dans un ArrayCollection - FLEX
J'ai une ArrayCollection d'objets triés.
Maintenant, je dois déplacer une ligne à la fin de l'ArrayCollection.
Pour illustrer,
arrayCollection = ["Cars","Other","Trucks"];
Cette ArrayCollection est triée. Maintenant, je dois déplacer 'Other'
à la fin de l'ArrayCollection. à savoir, j'ai besoin du tableau à être restructuré comme
arrayCollection = ["Cars","Trucks","Other"];
Voici mon code,
if(Index != -1){
CategoryList.addItem(CategoryList.removeItemAt(Index));
trace(CategoryList.source.join());}
« CatégorieListe » est une ArrayCollection de longueur 28, avec 3 attributs pour chaque objet dans le ArrayCollection.
'RemoveItem' fonctionne très bien, but'AddItem » jette cette erreur,
RangeError: Index '28' specified is out of bounds. at mx.collections::ArrayList/addItemAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ArrayList.as:305] at mx.collections::ListCollectionView/addItemAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:501] at mx.collections::ListCollectionView/addItem()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:470] at components::Home/creationOver()[C:\Documents and Settings\immanuel\My Documents\Flex Builder 3\Porj\src\components\Home.mxml:113] at components::Home/___Home_Canvas1_creationComplete()[C:\Documents and Settings\immanuel\My Documents\Flex Builder 3\Porj\src\components\Home.mxml:2] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298] at mx.core::UIComponent/set initialized()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1169] at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:718] at Function/ http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628] at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]
J'essaie alors d'insérer à une position spécifique,
CategoryList.addItemAt(CategoryList.removeItemAt(Index), CategoryList.length-1);
Mais cela, jette l'erreur ci-dessous,
TypeError: Error #1006: value is not a function. at mx.collections::ListCollectionView/getFilteredItemIndex()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:564] at mx.collections::ListCollectionView/addItemsToView()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:896] at mx.collections::ListCollectionView/listChangeHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1051] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.collections::ArrayList/internalDispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ArrayList.as:510] at mx.collections::ArrayList/addItemAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ArrayList.as:311] at mx.collections::ListCollectionView/addItemAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:501] at components::Home/creationOver()[C:\Documents and Settings\immanuel\My Documents\Flex Builder 3\Porj\src\components\Home.mxml:113] at components::Home/___Home_Canvas1_creationComplete()[C:\Documents and Settings\immanuel\My Documents\Flex Builder 3\Porj\src\components\Home.mxml:2] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298] at mx.core::UIComponent/set initialized()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1169] at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:718] at Function/ http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628] at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]
Enlever et ajouter à la fin des travaux. – Amarghosh
Merci pour la réponse, et pour confirmer cela fonctionne Amarghosh ... Je suis en train d'utiliser un ArrayCollection et les méthodes join, push et splice ne fonctionnent pas sur un ArrayCollection ... Je voulais juste rendre mon exigence plus simple :) – Immanuel
C'est plus facile avec la collection de tableaux - voir ma mise à jour. Vous devrez réinitialiser la propriété sort à null avant de faire cela. – Amarghosh