【问题标题】:Why is AdvancedDataGrid not updating when the HierarchicalData dataProvider is updated?为什么在更新 HierarchicalData dataProvider 时 AdvancedDataGrid 不更新?
【发布时间】:2009-02-26 20:05:50
【问题描述】:

我有一个带有 HierarchicalData 数据提供者的 AdvancedDataGrid (ADG):

<mx:AdvancedDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
    dataProvider="{__model.myHierarchicalData}" 
    displayItemsExpanded="true" sortExpertMode="true" dropEnabled="true" 
    sortableColumns="false" draggableColumns="false" 
    resizableColumns="true" textAlign="left" defaultLeafIcon="{null}" 
    folderOpenIcon="{null}" folderClosedIcon="{null}"/>

当我最初在 Model 中设置 HierarchicalData 实例时,它按预期显示:

function buildHierarchicalData(parentItems:ArrayCollection):void
{
    __model.myHierarchicalData = new HierarchicalData();

    __model.myHierarchicalData.source = parentItems;
}

parentItems 是 ParentItem valueObjects 的集合:

package
{
    [Bindable]
    public class ParentItem
    {
        public var children:ArrayCollection;

        public var label:String;
    }
}

但是,当我将子项从一个父项移动到另一个父项(通过拖放)时,更新不可见,使用以下代码:

function moveChildren(movedChildren:Array /* of ParentItem */):void
{
    parentItem.children = new ArrayCollection(movedChildren);
}

但是,由于某种原因,这确实有效:

function moveChildren(movedChildren:Array /* of ParentItem */):void
{
    parentItem.children.source = movedChildren;
}

为什么一定要更新ArrayCollection的来源???

【问题讨论】:

  • 尝试让孩子可以绑定。
  • 对不起,它可以在我的代码中绑定(参见上面的固定帖子)。

标签: apache-flex actionscript-3 hierarchical-data advanceddatagrid


【解决方案1】:

感谢 dirkgently 引导我找到答案。我现在不再需要在模型中使用 HierarchicalData 属性,而是在 MXML 中设置 Hierarchical dataProvider:

<mx:AdvancedDataGrid xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:dataProvider>
        <mx:HierarchicalData source="{__model.parentItems}" />
    </mx:dataProvider>
</mx:AdvancedDataGrid>

【讨论】:

    【解决方案2】:

    this。建议在处理dataProviders 时始终使用可绑定的ArrayCollection

    【讨论】:

    • 感谢您的链接。我在那里找到了答案。
    • 实际上,这使我的代码更好,但并没有解决我的问题。该类是可绑定的,但除非我更新项目的源,否则数据提供程序仍然无法正确更新。
    【解决方案3】:

    试试

    IHierarchicalCollectionView(__model.myHierarchicalData).refresh();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      相关资源
      最近更新 更多