0


0

ArrayCollection内の要素を移動する - FLEX

誰かが私を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’は正常に動作しますが、 'Adddtem’はこのエラーをスローします。

_ RangeError:指定されたインデックス '28’は範囲外です。 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 components :: Home / creationOver()[C:\ Documents and Settings \ immanuel \ My Documents \ Flex Builder 3 \ Porj \ src \ components \ Homeの\ projects \ framework \ src \ mx \ collections \ ListCollectionView.as:470] 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の.mxml:113] / dispatchEventFunction()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 initialize()[C:\ autobuild \ 3.2.0 \ frameworks \ p rojects \ 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] 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] 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] components :: Home / creでationOver()[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 initialize()[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] _ _

1 Answer


3


var array:Array = ["Cars", "Other", "Trucks"];
pushToEnd(array, 1);

trace(array.join()); //Cars,Trucks,Other

/**
* Removes the item at 'index' and pushes it to the back of the array.
*/

function pushToEnd(array:Array, index:Number):void
{
  array.push(array.splice(index, 1)[0]);
}

'' '' '

それは `ArrayCollection`を使うともっと簡単です

arrayCol.addItem(arrayCol.removeItemAt(index));

更新:実用サンプル - 自分で見てください。

            import mx.collections.ArrayCollection;

            private var ac:ArrayCollection;

            private function handle():void
            {
                ac.addItem(ac.removeItemAt(1));
                trace(ac.source.join());
            }

            private function create():void
            {
                ac = new ArrayCollection(["asd", "qwe", "zxc", "123"]);
                trace(ac.source.join());
            }