Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 水平列表控件的Flex拖放重新排序-从索引和到索引查找?_Apache Flex_Flex3_Drag And Drop - Fatal编程技术网

Apache flex 水平列表控件的Flex拖放重新排序-从索引和到索引查找?

Apache flex 水平列表控件的Flex拖放重新排序-从索引和到索引查找?,apache-flex,flex3,drag-and-drop,Apache Flex,Flex3,Drag And Drop,我有一个Flex3项目,有两个水平列表控件;其中一个已启用拖放功能。两个控件将始终具有相同数量的项,并且是相关的。。。第一个控件的索引0与第二个控件的索引0匹配,依此类推 当然,当使用拖放对第二个控件重新排序时,我希望第一个控件中的项反映相同的重新排序。我想我可以处理控件的实际更新,但是我很难找到通过拖放移动的项的from和to索引 在允许拖放的控件上使用dragDrop方法,并在调试器中仔细阅读event.currentTarget(而不是event.target)的内容,显示名为select

我有一个Flex3项目,有两个水平列表控件;其中一个已启用拖放功能。两个控件将始终具有相同数量的项,并且是相关的。。。第一个控件的索引0与第二个控件的索引0匹配,依此类推

当然,当使用拖放对第二个控件重新排序时,我希望第一个控件中的项反映相同的重新排序。我想我可以处理控件的实际更新,但是我很难找到通过拖放移动的项的fromto索引

在允许拖放的控件上使用
dragDrop
方法,并在调试器中仔细阅读
event.currentTarget
(而不是
event.target
)的内容,显示名为
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并不重要(它们还没有太多代码),因此为了简洁起见,我将把它们省略掉。如果您认为它们很重要,请告诉我,我将在此处编辑它们。

结果表明,解决方案是从使用
dragDrop
事件切换到
dragComplete
事件;此时,绑定的数据提供程序已更新,以反映重新排序。

这就是为什么要创建模型定位器模式

您必须将数据提供程序移动到一个单例类(例如模型),这样您的项目呈现程序才能轻松访问它。您的项没有属性索引,因为它已经由[ArrayCollection].getItemIndex(..)给定