在另一个数据网格的更改事件上更改数据网格的数据提供者
我有两个数据网格: - 分配 - 会员 两者都有单列。从部门数据网格中选择一项应在成员数据网格中显示该部门的成员。但是下面的代码有一些问题,当单击相应的部门时,特定部门的成员不会显示。
以下是相关代码的一些片段。希望有人能够发现其中的错误。
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>
I have two datagrids:
- Division
- Members
Both have single columns. Selecting one item from Divsions datagrid should display members of that Division in the Members datagrid. But following code has some problem and Members of a particular division do not show up when respective Divsion is clicked.
Following are some snippets of the related code. Hope someone can spot an error in it.
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意您的条件语句。
应该是
http://livedocs.adobe.com/flex /3/html/help.html?content=03_Language_and_Syntax_15.html
Take care to your conditionals statements.
should be
http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_15.html
将此行添加到方法 divDataGridChange() 中:
memDataGrid.invalidateDisplayList();
更新的方法:
还将事件从“change”替换为“itemclick“。部门数据网格标签将是
Add this line to the method divDataGridChange() :
memDataGrid.invalidateDisplayList();
Updated method :
Also replace the event from "change" to "itemclick".The divisions datagrid tag will be