我有一個帶有2個HorizontalList控件的Flex3項目;其中一個拖動已啓用&拖放。兩個控件始終具有相同數量的項目,並且相關...第一個控件的索引0與第二個控件的索引0匹配,以此類推。Flex拖放一個HorizontalList控件的重新排序 - 查找FROM和TO索引?
當然,使用拖放操作重新排序第二個控件時,我希望第一個控件中的項目反映相同的重新排序。我想我可以處理控件的實際更新,但我無法找到從和到已通過拖動&拖放移動的項目的索引。
使用的控制dragDrop
方法,它允許拖放,並在調試細讀的event.currentTarget
(而不是event.target
because the docs say so)中的內容顯示了一個名爲selectedIndex
這似乎持有從指數的公共屬性,但我沒有看到任何屬性會告訴我到索引。
我可以俯瞰酒店嗎?我必須根據別的東西推斷它嗎?有一個更好的方法嗎?
更新:可接受的解決方案也可能是迭代HorizontalList將內容並保存內部索引值然後可用於爲其他列表重新排序的數據提供程序的陣列;但我無法弄清楚如何迭代列表內容,所以我就像被卡住了一樣。有什麼幫助嗎?
這裏是我的代碼:
main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:com="components.*"
layout="absolute"
>
<mx:Script>
<![CDATA[
import mx.events.DragEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
//these two variables are junk data to represent
//what we will get back from our data services...
[Bindable]
private var btnData:ArrayCollection = new ArrayCollection(
[
{title:'title1', index:0},
{title:'title2', index:1},
{title:'title3', index:2},
{title:'title4', index:3}
]
);
[Bindable]
private var chainData:ArrayCollection = new ArrayCollection(
[
{tmp:'testing 1'},
{tmp:'testing 2'},
{tmp:'testing 3'},
{tmp:'testing 4'}
]
);
//handle button re-ordering
private function handleBtnReorder(event:DragEvent):void{
Alert.show(event.action.toString());
}
]]>
</mx:Script>
<mx:HorizontalList
id="ChainView"
dataProvider="{chainData}"
itemRenderer="components.ItemRenderers.ChainLinkRenderer"
left="20"
right="20"
top="20"
height="300"
rowHeight="300"
columnWidth="500"
rollOverColor="#ffffff"
selectionColor="#eeeeee"
/>
<mx:HorizontalList
id="btnList"
dataProvider="{btnData}"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
dragDrop="handleBtnReorder(event)"
itemRenderer="components.ItemRenderers.BtnListRenderer"
horizontalCenter="true"
left="20"
right="20"
top="320"
height="50"
rowHeight="35"
rollOverColor="#ffffff"
selectionColor="#ffffff"
/>
</mx:Application>
的Alert.show(...)
是不是有顯示有用的東西,我已經設置在該行斷點,這樣我可以檢查事件參數。
我不認爲自定義itemRenderer是重要的(但它們沒有太多代碼),所以爲了簡潔起見,我將它們排除在外。如果你認爲他們是重要,請告訴我,我會在這裏編輯它們。