You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Adobe Flex(ActionScript)中选中Grid行时如何获取行数据填充下方文本字段

解决方法

Flex的DataGrid组件内置了selectedItem属性,会直接返回当前选中行绑定的完整数据对象,不需要通过event.target获取单元格内容,你之前的写法只能拿到点击位置的单个单元格数据。

代码修改

仅需要替换你代码中的dada函数即可:

public function dada(event:Event):void
{
    // 先判断是否存在选中行,避免空引用报错
    if(myGrid.selectedItem == null) return;
    // 此处的name/age/hobby/phone请替换为你自己XML中Contact节点对应的子节点名称
    naam.text = myGrid.selectedItem.name.toString();
    age.text = myGrid.selectedItem.age.toString();
    hobby.text = myGrid.selectedItem.hobby.toString();
    phone.text = myGrid.selectedItem.phone.toString();
}

可选优化

你可以把DataGrid的触发事件从click换成selectionChange,也就是将<mx:DataGrid>标签中的click="dada(event)"修改为selectionChange="dada(event)",这样不管是鼠标点击选中还是用键盘上下切换选中行,都会自动触发字段填充,交互体验更合理。

内容的提问来源于stack exchange,提问作者Chaitanya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 03:00:00