2011-10-15 95 views
0

我有两个数据网格: - 部门 - 成员 两者都有单列。从Divsions数据网格中选择一个项目应该在成员数据网格中显示该项目的成员。但是下面的代码有一些问题,并且当各个Divsion被点击时某个分区的成员不会显示。在另一个数据网格的更改事件中更改数据网格的数据提供者

以下是相关代码的一些片段。希望有人可以发现它的错误。

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> 

回答

2

注意您的条件声明。

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

+0

哦。谢谢。但问题仍然存在,即单击Divisions的datagrid项目时,会员的数据网格项目不会发生变化。 : - / – baltoro

0

此行添加到方法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(); 
     } 

同样来自 “变化” 更换事件 “itemClick在” .The部门DataGrid的标签将

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