【发布时间】:2010-12-16 23:09:23
【问题描述】:
有人可以引导我在 flex 的 ArrayCollection 中移动一个元素吗?
我有一个排序对象的 ArrayCollection。
现在我需要将一行移动到 ArrayCollection 的末尾。
为了说明,
arrayCollection = ["Cars","Other","Trucks"];
此 ArrayCollection 已排序。现在我需要将'Other' 移动到 ArrayCollection 的末尾。即,我需要将数组重组为
arrayCollection = ["Cars","Trucks","Other"];
这是我的代码,
if(Index != -1){
CategoryList.addItem(CategoryList.removeItemAt(Index));
trace(CategoryList.source.join());}
'CategoryList' 是一个长度为 28 的 ArrayCollection,ArrayCollection 中的每个对象都有 3 个属性。
'RemoveItem' 工作正常,但'AddItem' 抛出此错误,
RangeError:指定的索引“28”超出范围。 在 mx.collections::ArrayList/addItemAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ArrayList.as:305] 在 mx.collections::ListCollectionView/addItemAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:501] 在 mx.collections::ListCollectionView/addItem()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:470] 在 components::Home/creationOver()[C:\Documents and Settings\immanuel\My Documents\Flex Builder 3\Porj\src\components\Home.mxml:113] 在 components::Home/___Home_Canvas1_creationComplete()[C:\Documents and Settings\immanuel\My Documents\Flex Builder 3\Porj\src\components\Home.mxml:2] 在 flash.events::EventDispatcher/dispatchEventFunction() 在 flash.events::EventDispatcher/dispatchEvent() 在 mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298] 在 mx.core::UIComponent/set initialized()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1169] 在 mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:718] 在函数/http://adobe.com/AS3/2006/builtin::apply() 在 mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628] 在 mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]
然后我尝试在特定位置插入,
CategoryList.addItemAt(CategoryList.removeItemAt(Index), CategoryList.length-1);
但这会引发以下错误,
TypeError:错误 #1006:值不是函数。 在 mx.collections::ListCollectionView/getFilteredItemIndex()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:564] 在 mx.collections::ListCollectionView/addItemsToView()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:896] 在 mx.collections::ListCollectionView/listChangeHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1051] 在 flash.events::EventDispatcher/dispatchEventFunction() 在 flash.events::EventDispatcher/dispatchEvent() 在 mx.collections::ArrayList/internalDispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ArrayList.as:510] 在 mx.collections::ArrayList/addItemAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ArrayList.as:311] 在 mx.collections::ListCollectionView/addItemAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:501] 在 components::Home/creationOver()[C:\Documents and Settings\immanuel\My Documents\Flex Builder 3\Porj\src\components\Home.mxml:113] 在 components::Home/___Home_Canvas1_creationComplete()[C:\Documents and Settings\immanuel\My Documents\Flex Builder 3\Porj\src\components\Home.mxml:2] 在 flash.events::EventDispatcher/dispatchEventFunction() 在 flash.events::EventDispatcher/dispatchEvent() 在 mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298] 在 mx.core::UIComponent/set initialized()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1169] 在 mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:718] 在函数/http://adobe.com/AS3/2006/builtin::apply() 在 mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628] 在 mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]
【问题讨论】:
标签: apache-flex actionscript-3