【问题标题】:AdvancedDataGrid Problem (Bug?) -- Disclosure Icons in Wrong Column. (Hierarchical data, Flex 3.5)AdvancedDataGrid 问题(错误?)- 错误列中的披露图标。 (分层数据,Flex 3.5)
【发布时间】:2011-04-10 20:47:04
【问题描述】:

我遇到了一个有趣的问题,并认为值得发布:

在我必须在运行时使用分层数据设置数据提供者的情况下,我使用了高级数据网格。 adobe 文档并没有真正涵盖这种事情(至少在我可以挖掘到的水平上)。

以前有人遇到过这种情况吗?

我唯一能想到的是有点骇人听闻,并且似乎在高级网格的披露图标中引入了一些奇怪的行为。我在下面包含了一个测试用例:

advancedDataGridProblem.as:

 import mx.collections.ArrayCollection;

 public var dataProvider:ArrayCollection = new ArrayCollection([{label:"item1"},
             {label:"item2", children:[{label:"subItem1"},{label:"subItem2"},
             {label:"subItem3"}]},
             {label:"item3"}]);

 public function init():void{
      //using callLater to ensure that the grid has been created before setting DP
      this.callLater(setDataProvider,[dataProvider]);
 }

 public function setDataProvider(list:ArrayCollection):void{
      heirData.source = list;
 }

和mxml:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
     <mx:Script source="advancedDataGridProblem.as"/>


  <mx:AdvancedDataGrid id="advDG" width="100%">

   <mx:columns>
        <mx:AdvancedDataGridColumn headerText="What the heck?"/>
        <mx:AdvancedDataGridColumn headerText="Label" dataField="label"/>
        <mx:AdvancedDataGridColumn headerText="Column 2"/>
        <mx:AdvancedDataGridColumn headerText="Column 3"/>
   </mx:columns>

   <mx:dataProvider>
        <mx:HierarchicalData id="heirData"/>
   </mx:dataProvider>
 </mx:AdvancedDataGrid>

</mx:Application>

正如您在运行测试应用程序时所看到的,应该显示在“标签”列中的图标实际上被放置在“What the heck?”中。柱子。如果您将 Label 列拖过来并尝试将其与“What the heck?”交换。列,图标保持在原来的位置,但神奇的是,以前为“标签”列左对齐的标签现在为图标设置了适当的格式。将“标签”列拖出插槽 1 会将网格恢复为原始状态。

这个有点超出我的想象 - 有人有什么建议吗?

理想情况下,我想一起解决这个问题,并在运行时像往常一样分配 dataProvider。

提前致谢!

我将很快向 adobe 提交一份关于此问题的错误报告,并将链接放入评论中。

【问题讨论】:

    标签: flex3 advanceddatagrid dataprovider hierarchical disclosure


    【解决方案1】:

    嗯..

    在一个周末让我的头好好地摇晃一下,今天我的眼睛焕然一新,我找到了解决我问题中“简单”部分的方法。

    直接设置AdvancedDataGrid的dataProvider比我原先想象的要简单得多;您只需要将 ArrayCollection 转换为 HierarchicalData。老实说,我之前尝试过这个,但是拼写错误 Hierarchical.. facepalm.

    总之,advancedDataGridProblem.as 应该改成:

    import mx.collections.ArrayCollection;
    import mx.collections.HierarchicalData;
    
    public var dataProvider:ArrayCollection = new ArrayCollection([{label:"item1"},
                                                                    {label:"item2", children:[{label:"subItem1"},{label:"subItem2"},
                                                                    {label:"subItem3"}]},
                                                                    {label:"item3"}]);
    
    public function init():void{
        //using callLater to ensure that the grid has been created before setting DP
        this.callLater(setDataProvider,[dataProvider]);
    }
    
    public function setDataProvider(list:ArrayCollection):void{
        advDG.dataProvider = new HierarchicalData(list);
    }
    

    mxml中dataProvider的声明也可以去掉:

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
     <mx:Script source="advancedDataGridProblem.as"/>
    
    
    <mx:AdvancedDataGrid id="advDG" width="100%">
    
     <mx:columns>
        <mx:AdvancedDataGridColumn headerText="What the heck?"/>
        <mx:AdvancedDataGridColumn headerText="Label" dataField="label"/>
        <mx:AdvancedDataGridColumn headerText="Column 2"/>
        <mx:AdvancedDataGridColumn headerText="Column 3"/>
     </mx:columns>
     </mx:AdvancedDataGrid>
    
    </mx:Application>
    

    运行此代码,您仍然可以在错误的列中看到披露图标,但至少删除了在 mxml 中设置网格的 dataProvider 的“hackish”解决方案。这样做还允许正确的验证和网格的显示。设置网格的 dataProvider 允许正确的显示验证,显然设置它的 dataProvider 的分层数据源不会调用那些相同的验证方法,需要用户调整网格大小或程序员以某种方式强制验证(这在我的一生中我不能做)。

    我会及时通知您披露图标问题。同时,我希望锁定第一列并将其仅用于这些图标在我的应用程序中会很好。我什至可以把这个“缺陷”变成一个“功能”:P

    干杯!

    [编辑]

    在使用绑定数据时允许更轻松实施和更少业务逻辑的另一种方法是:

    advancedDataGridProblem.as:

    import mx.collections.ArrayCollection;
    import mx.collections.HierarchicalData;
    
    public var dataProvider:ArrayCollection = new ArrayCollection([{label:"item1"},
                                                                    {label:"item2", children:[{label:"subItem1"},{label:"subItem2"},
                                                                    {label:"subItem3"}]},
                                                                    {label:"item3"}]);
    

    mxml:

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
     <mx:Script source="advancedDataGridProblem.as"/>
    
    
    <mx:AdvancedDataGrid id="advDG" width="100%">
    
     <mx:columns>
        <mx:AdvancedDataGridColumn headerText="What the heck?"/>
        <mx:AdvancedDataGridColumn headerText="Label" dataField="label"/>
        <mx:AdvancedDataGridColumn headerText="Column 2"/>
        <mx:AdvancedDataGridColumn headerText="Column 3"/>
     </mx:columns>
    
     <mx:dataProvider>
         <mx:HierarchicalData source="{dataProvider}"/>
     </mx:dataProvider>
    
     </mx:AdvancedDataGrid>
    
    </mx:Application>
    

    这种方法避免了在 ActionScript 中设置网格的 dataProvider 后必须手动使网格的列表、显示列表等无效和验证的可能问题。我对使用这种方法的一个小保留是,因为这会在 flex 3 中创建单向绑定,所以我不确定是否能够使用 HierarchicalData 对象的方法来更改绑定的 ArrayCollection。也就是说,我没有在 HierarchicalData 或 AdvancedDataGrid 的源代码中四处寻找,但我不会怀疑它们会直接更改源代码。我会在结果出来时发布结果。

    干杯!

    【讨论】:

      【解决方案2】:

      要解决上述披露图标问题,您可以指定 AdvancedDataGrid 的“treeColumn”属性,并传递您的树数据应位于的列的 id。

      显然,前几天我在看 livedocs 时失明了。

      干杯!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多