在另一个数据网格的更改事件上更改数据网格的数据提供者

发布于 2024-12-10 01:11:49 字数 1524 浏览 0 评论 0原文

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

以下是相关代码的一些片段。希望有人能够发现其中的错误。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咽泪装欢 2024-12-17 01:11:49

请注意您的条件语句。

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

Take care to your conditionals statements.

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

should be

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

花海 2024-12-17 01:11:49

将此行添加到方法 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“。部门数据网格标签将是

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

Add this line to the method divDataGridChange() : memDataGrid.invalidateDisplayList();

Updated method :

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();
        }

Also replace the event from "change" to "itemclick".The divisions datagrid tag will be

<mx:DataGrid id="divDataGrid" dataProvider="{divisions}" width="150" height="265" itemClick="{divDataGridChange()}" selectedIndex="0" >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文