带分层数据的 Flex 高级数据网格:如何在拖放事件上访问 currentTarget 字段?

发布于 2024-10-16 21:38:35 字数 940 浏览 10 评论 0原文

所以这让我发疯。我有一个带有数据提供者的高级数据网格,该数据提供者是带有分层数据的数组集合。每个对象(包括子对象)都有一个 id 字段。我正在尝试从 ADG 中拖放数据。发生这种情况时,我需要从放置目标中获取 id 并更改拖动对象的parentid 字段。这就是我所得到的:

public function topAccountsGrid_dragDropHandler(event:DragEvent):void{  
    //In this function, you need to make the move, update the field in salesforce, and refresh the salesforce data...
    if(checkActivateAccountManageMode.selected == true) {
        var dragObj:Array = event.dragSource.dataForFormat("treeDataGridItems") as Array;
        var newParentId:String = event.currentTarget['Id'];
        dragObj[0].ParentId = newParentId;
    } else {
        return;
    }
    app.wrapper.save(dragObj[0], 
        new mx.rpc.Responder(
            function():void {
            refreshData();
        },
        function():void{_status = "apex error!";}
        )
    );
}

我可以访问我正在拖动的数据(因此更改parentId),但不能访问currentTarget。我认为分层数据是问题的一部分,但我在文档中找不到太多内容?有什么想法吗?

So this is driving me crazy. I've got an advanced data grid with a dataprovider that's an array collection w/ hierarchical data. Each object (including the children) has an id field. I'm trying to drag and drop data from within the ADG. When this happens, I need to grab the id off the drop target and change the dragged object's parentid field. Here's what I've got:

public function topAccountsGrid_dragDropHandler(event:DragEvent):void{  
    //In this function, you need to make the move, update the field in salesforce, and refresh the salesforce data...
    if(checkActivateAccountManageMode.selected == true) {
        var dragObj:Array = event.dragSource.dataForFormat("treeDataGridItems") as Array;
        var newParentId:String = event.currentTarget['Id'];
        dragObj[0].ParentId = newParentId;
    } else {
        return;
    }
    app.wrapper.save(dragObj[0], 
        new mx.rpc.Responder(
            function():void {
            refreshData();
        },
        function():void{_status = "apex error!";}
        )
    );
}

I can access the data I'm draggin (hence changing parentId) but not the currentTarget. I think the hierarchical data is part of the problem, but I can't find much in the documentation? Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

预谋 2024-10-23 21:38:35

event.currentTarget 不是节点,它是 ADG 本身。但是,获取所需信息非常容易,因为 ADG 在内部存储该数据(作为 mx_internal)。

我在 dragOver 处理程序中使用以下代码片段(使用 Flex SDK 4.1 进行测试),但我想它也可以在 dragDrop 处理程序中工作。

protected function myGrid_dragDropHandler(event:DragEvent):void
{
    // Get the dragged items. This could either be an Array, a Vector or NULL.
    var draggedItems:Object = getDraggedItems(event.dragSource);

    if (!draggedItems)
        return;

    // That's our ADG where the event handler is registered.
    var dropTarget:AdvancedDataGrid = AdvancedDataGrid(event.currentTarget);

    // Get the internal information about the dropTarget from the ADG.
    var dropData:Object = mx_internal::dropTarget._dropData;

    // In case the dataProvider is hierarchical, get the internal hierarchicalData aka rootModel.
    var hierarchicalData:IHierarchicalData = dropTarget.mx_internal::_rootModel;
    var targetParent:Object = null;

    // If it's a hierarchical data structure and the dropData could be retrieved
    // then get the parent node to which the draggedItems are going to be added.
    if (hierarchicalData && dropData)
        targetParent = dropData.parent;

    for each (var draggedItem:Object in draggedItems)
    {
        // do something with the draggedItem
    }
}

protected function getDraggedItems(dragSource:DragSource):Object
{
    if (dragSource.hasFormat("treeDataGridItems"))
        return dragSource.dataForFormat("treeDataGridItems") as Array;

    if (dragSource.hasFormat("items"))
        return dragSource.dataForFormat("items") as Array;

    if (dragSource.hasFormat("itemsByIndex"))
        return dragSource.dataForFormat("itemsByIndex") as Vector.<Object>;

    return null;
}

event.currentTarget is not a node, it's the ADG itself. However, it's quite easy to get the information you want, since the ADG stores that data internally (as mx_internal).

I'm using the following code snippets (tested with Flex SDK 4.1) in a dragOver handler, but I guess it will work in a dragDrop handler too.

protected function myGrid_dragDropHandler(event:DragEvent):void
{
    // Get the dragged items. This could either be an Array, a Vector or NULL.
    var draggedItems:Object = getDraggedItems(event.dragSource);

    if (!draggedItems)
        return;

    // That's our ADG where the event handler is registered.
    var dropTarget:AdvancedDataGrid = AdvancedDataGrid(event.currentTarget);

    // Get the internal information about the dropTarget from the ADG.
    var dropData:Object = mx_internal::dropTarget._dropData;

    // In case the dataProvider is hierarchical, get the internal hierarchicalData aka rootModel.
    var hierarchicalData:IHierarchicalData = dropTarget.mx_internal::_rootModel;
    var targetParent:Object = null;

    // If it's a hierarchical data structure and the dropData could be retrieved
    // then get the parent node to which the draggedItems are going to be added.
    if (hierarchicalData && dropData)
        targetParent = dropData.parent;

    for each (var draggedItem:Object in draggedItems)
    {
        // do something with the draggedItem
    }
}

protected function getDraggedItems(dragSource:DragSource):Object
{
    if (dragSource.hasFormat("treeDataGridItems"))
        return dragSource.dataForFormat("treeDataGridItems") as Array;

    if (dragSource.hasFormat("items"))
        return dragSource.dataForFormat("items") as Array;

    if (dragSource.hasFormat("itemsByIndex"))
        return dragSource.dataForFormat("itemsByIndex") as Vector.<Object>;

    return null;
}
心病无药医 2024-10-23 21:38:35
var dropData:Object = mx_internal::dropTarget._dropData; 

应该

var dropData:Object = dropTarget.mx_internal::_dropData;

试试这个。

var dropData:Object = mx_internal::dropTarget._dropData; 

should be

var dropData:Object = dropTarget.mx_internal::_dropData;

Try this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文