apache-flex - 尝试获取数据网格所选项目的全局 y 坐标

标签 apache-flex actionscript-3

情况是这样的:
我有一个填充的数据网格,我想将表单移动到与数据网格的 selectedItem 内联(相同的 y 位置)。我不能依赖 mouseClick 事件,因为所选项目可能会随着键盘事件而更改。数据网格没有 itemRenderer,只是普通的旧数据字段。
有人以前做过吗?

这里有一些基于 Jacob 的答案的示例代码,供所有感兴趣的人使用。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               minWidth="955" minHeight="600">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;
            import mx.events.ListEvent;
            import mx.formatters.DateFormatter;

            [Bindable] public var ac_POitems:ArrayCollection = new ArrayCollection();
            [Bindable] public var selectedY:int;

            protected function dg_POitems_creationCompleteHandler(event:FlexEvent):void
            {
                //TODO
            }

            protected function submit_clickHandler(event:MouseEvent):void
            {
                //TODO
            }

            protected function format_sqlite_date(item:Object, col:DataGridColumn):String
            {
                var df:DateFormatter = new DateFormatter();
                df.formatString = "MM/DD/YYYY";
                var value:Object = item[col.dataField];
                return df.format(value);
            }

            protected function dg_POitems_changeHandler(event:ListEvent):void
            {
                trace(event.itemRenderer.y);
                selectedY = event.itemRenderer.y;
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <mx:VBox width="100%" height="100%" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
        <mx:DataGrid id="dg_POitems" dataProvider="{ac_POitems}" creationComplete="dg_POitems_creationCompleteHandler(event)" 
                     editable="true" height="100%" change="dg_POitems_changeHandler(event)">
            <mx:columns>
                <mx:DataGridColumn headerText="Consumer" dataField="consumer" editable="false"/>
                <mx:DataGridColumn headerText="Description" dataField="description" width="300" editable="false"/>
                <mx:DataGridColumn headerText="Amount" dataField="item_cost" editable="false" width="55"/>
                <mx:DataGridColumn headerText="Service Date" dataField="service_date" labelFunction="format_sqlite_date"/>
                <mx:DataGridColumn headerText="Invoice Date" dataField="invoice_date" labelFunction="format_sqlite_date"/>
                <mx:DataGridColumn headerText="Paid Date" dataField="payment_received" labelFunction="format_sqlite_date"/>
            </mx:columns>
        </mx:DataGrid>
    </mx:VBox>
    <mx:Form id="form_POItemDateEditor" label="{dg_POitems.selectedItem.consumer}" x="{dg_POitems.x + dg_POitems.width + 10}" 
             y="{selectedY + 10}" visible="{dg_POitems.selectedItem}" borderColor="#ffffff">
        <s:Label text="edit {dg_POitems.selectedItem.consumer}" width="100%" textAlign="center" verticalAlign="middle" fontWeight="bold" textDecoration="underline"/>
        <mx:FormItem label="Service Date">
            <mx:DateField id="service_date"/>
        </mx:FormItem>
        <mx:FormItem label="Invoie Date">
            <mx:DateField id="invoice_date"/>
        </mx:FormItem>
        <mx:FormItem label="Paid Date">
            <mx:DateField id="payment_received"/>
        </mx:FormItem>
        <mx:FormItem>
            <s:Button id="submit" label="Submit" click="submit_clickHandler(event)"/>
        </mx:FormItem>
    </mx:Form>
</s:Application>

最佳答案

这应该可以帮助您开始:

<fx:Script>
    <![CDATA[
        import mx.events.ListEvent;
        protected function datagrid1_changeHandler(event:ListEvent):void
        {
            trace(event.itemRenderer.y);

        }

    ]]>
</fx:Script>

<mx:DataGrid dataProvider="{steps}" change="datagrid1_changeHandler(event)" >
    ....

编辑显示 spark:List valueCommit 事件的监听器。

protected function valueCommitHandler(event:FlexEvent):void
    {
        trace(event.currentTarget.layout.getElementBounds(list.selectedIndex));
    }

关于apache-flex - 尝试获取数据网格所选项目的全局 y 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6959867/

相关文章:

apache-flex - 对象的闪存复制 - 克隆库?

apache-flex - 现在转移到 Flex SDK 4 还为时过早吗?

youtube - 从 as3 中的 youtube 播放列表中获取视频 ID

actionscript-3 - 在ActionScript(3.0)中干净地合并两个数组?

javascript - Flex 捕获应用程序上的所有鼠标点击

actionscript-3 - AIR AS3 投影仪的奇怪错误

apache-flex - Flex Web App 自动化测试

actionscript-3 - 为影片剪辑的特定子级禁用鼠标事件

c# - C# Flash 回调的简单例子

flash - 如何在AS3中修改运动跟踪