简体   繁体   English

Flex:在函数中使用DateGrid的selectedItem

[英]Flex: use the selectedItem of DateGrid in an function

I'm using a spark Datagrid in an mobile Flex (4.6) application. 我在移动Flex(4.6)应用程序中使用spark Datagrid。 When a row is selected in the grid I want to trigger a function and use the content of the selected item in that same function. 当在网格中选择一行时,我想触发一个功能并在同一功能中使用所选项目的内容。 This is my Datagrid 这是我的Datagrid

<s:DataGrid id="patientGrid" x="317" y="211" width="393" height="177"
            dataProvider="{patientInfo}" gridClick="patientSelect(event)">
    <s:columns>
        <s:ArrayList>
            <s:GridColumn dataField="FirstName" headerText="First Name"/>
            <s:GridColumn dataField="LastName" headerText="Last Name"/>
            <s:GridColumn dataField="DateOfBirth" headerText="Date Of Birth"/>
            <s:GridColumn dataField="Gender" headerText="Gender"/>
        </s:ArrayList>
    </s:columns>
</s:DataGrid>

And when a item is selected the patientselected function needs the ability to work with the content of that selected item. 并且当选择一个项目时,患者选择的功能需要具有处理该选择项目的内容的能力。

I hope my question is clear, and thanks for helping! 我希望我的问题很清楚,并感谢您的帮助!

Use the GridSelectionEvent.SELECTION_CHANGE event instead for two reasons: 改用GridSelectionEvent.SELECTION_CHANGE事件有两个原因:

  • it will provide information on which cells have been selected 它将提供有关已选择哪些单元格的信息
  • it is fired whenever the selection changes (if you only react on mouse clicks, you ignore keyboard navigation/selection) 每当选择更改时都会触发(如果您仅对鼠标单击做出反应,则忽略键盘导航/选择)

.

<s:DataGrid id="dg" selectionChange="onSelectionChange(event)" />

private function onSelectionChange(event:GridSelectionEvent):void {
    var index:int = event.selectionChange.rowIndex;
    var patient = dg.dataProvider.getItemAt(index);
    patientSelect(patient);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM