【问题标题】:Changing dataprovider of a datagrid on change event of another datagrid在另一个数据网格的更改事件上更改数据网格的数据提供者
【发布时间】:2011-10-15 10:06:49
【问题描述】:

我有两个数据网格: - 分配 - 成员 两者都有单列。从部门数据网格中选择一项应在成员数据网格中显示该部门的成员。但是下面的代码有一些问题,当点击相应的分部时,特定分部的成员不显示。

以下是相关代码的一些sn-ps。希望有人能发现其中的错误。

private var divs_array:Array = ['Division A','Division B'];
[Bindable] private var divisions:ArrayCollection = new ArrayCollection(divs_array);

private var memA_array:Array = ['Jo Koy','Stephan Lynch', 'Charlie Murphy', 'Michael'];
[Bindable] private var mems_of_A :ArrayCollection = new ArrayCollection(memA_array);

private var memB:Array = ['Ali','Ikram'];
[Bindable] private var mems_of_B:ArrayCollection = new ArrayCollection(memB_array);         

private function divDataGridChange():void{
  if (divDataGrid.selectedIndex==0)
    memDataGrid.dataProvider=mems_of_A;
  else (divDataGrid.selectedIndex==1)
    memDataGrid.dataProvider=mems_of_B;
}

private function getCombinedUserNameLabel(item:Object, col:DataGridColumn):String
{
    return item.firstName + " " + item.lastName;
}

<mx:DataGrid id="divDataGrid" dataProvider="{divisions}" width="150" height="265" change="{divDataGridChange()}" selectedIndex="0">
  <mx:columns>
    <mx:DataGridColumn width="150" headerText="Select a Division" />
  </mx:columns>
</mx:DataGrid>
<mx:DataGrid id="memDataGrid" dataProvider="{mems_of_A}" change="{monDataGridChange()}" selectedIndex="0">
  <mx:columns>
    <mx:DataGridColumn width="150" headerText="Select a User" labelFunction="{getCombinedUserNameLabel}" />
  </mx:columns>
</mx:DataGrid>

【问题讨论】:

    标签: apache-flex actionscript flex4 flexbuilder flex4.5


    【解决方案1】:

    注意你的条件语句。

    private function divDataGridChange():void{
      if (divDataGrid.selectedIndex==0)
        memDataGrid.dataProvider=mems_of_A;
      else (divDataGrid.selectedIndex==1)
        memDataGrid.dataProvider=mems_of_B;
    }
    

    应该是

    private function divDataGridChange():void{
      if (divDataGrid.selectedIndex==0)
        memDataGrid.dataProvider=mems_of_A;
      else if (divDataGrid.selectedIndex==1)
        memDataGrid.dataProvider=mems_of_B;
    }
    

    http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_15.html

    【讨论】:

    • 哦。谢谢你。但问题仍然存在,即成员的数据网格项目在单击部门的数据网格项目时不会改变。 :-/
    【解决方案2】:

    将此行添加到方法 divDataGridChange() :memDataGrid.invalidateDisplayList();

    更新方法:

    private function divDataGridChange():void{
                if (divDataGrid.selectedIndex==0)
                    memDataGrid.dataProvider=mems_of_A;
                else if (divDataGrid.selectedIndex==1)
                    memDataGrid.dataProvider=mems_of_B;
    
                memDataGrid.invalidateDisplayList();
            }
    

    还将事件从“change”替换为“itemclick”。divings datagrid 标签将是

    <mx:DataGrid id="divDataGrid" dataProvider="{divisions}" width="150" height="265" itemClick="{divDataGridChange()}" selectedIndex="0" >
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      • 2012-02-08
      • 2019-03-03
      • 1970-01-01
      相关资源
      最近更新 更多