数据网格中的 Itemclick 事件
该问题可以概括为当单击数据网格中的项目时,文本区域显示该项目的值,但这里的组件是独立的,因此需要调度事件。
My mxml component file :
<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml" itemClick="itemClickEvent(event);" creationComplete="init()">
<mx:Metadata>
[Event(name="IdSelected", type="one.IdEvent")]
</mx:Metadata>
<mx:Script>
<![CDATA[ import genericReport.*;
import crewUtilization.*;
import utils.*;
import studies.*;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.events.ListEvent;
private function itemClickEvent(event:ListEvent):void
{
var _study:Object=event.currentTarget.selectedItem.study;
dispatchEvent(new IDEvent(_ID));
}
]]>
</mx:Script>
<mx:columns>
<mx:DataGridColumn dataField="name" />
<mx:DataGridColumn dataField="userId" />
</mx:columns>
</mx:DataGrid>
/////////////////////////////////////////////////////////// /////////////
这是我的主 MXML 应用程序文件:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:custom="*">
<mx:TitleWindow label="Scenario Creation" xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:ns1="ccCreation.*">
<mx:Label text="CC CREATION" width="100%" />
<mx:VBox width="100 %" styleName="scenariovboxStyle">
<custom:studySelector id="dg" />
</mx:VBox>
</mx:TitleWindow>
</mx:Application>
The problem can be summarized as when clicking an item in datagrid, the text area shows the value of the item, but here the compoents are separate and hence events need to be dispatched.
My mxml component file :
<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml" itemClick="itemClickEvent(event);" creationComplete="init()">
<mx:Metadata>
[Event(name="IdSelected", type="one.IdEvent")]
</mx:Metadata>
<mx:Script>
<![CDATA[ import genericReport.*;
import crewUtilization.*;
import utils.*;
import studies.*;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.events.ListEvent;
private function itemClickEvent(event:ListEvent):void
{
var _study:Object=event.currentTarget.selectedItem.study;
dispatchEvent(new IDEvent(_ID));
}
]]>
</mx:Script>
<mx:columns>
<mx:DataGridColumn dataField="name" />
<mx:DataGridColumn dataField="userId" />
</mx:columns>
</mx:DataGrid>
///////////////////////////////////////////////////////////////
This is my Main MXML Application file :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:custom="*">
<mx:TitleWindow label="Scenario Creation" xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:ns1="ccCreation.*">
<mx:Label text="CC CREATION" width="100%" />
<mx:VBox width="100 %" styleName="scenariovboxStyle">
<custom:studySelector id="dg" />
</mx:VBox>
</mx:TitleWindow>
</mx:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为studyId引用dataGrid可能比dataGrid引用studyId更好。 您可以将其添加到您的主 mxml 中:
这应该可以工作,因为 TextArea.text 将响应 DataGrid.selectedItem 的属性更改事件,因此只要选择更改,它就会更改。
编辑:调度事件:
您可以从代码中的任何位置调度事件,并且侦听器将能够侦听该事件。 例如:
现在您可以收听该事件:
希望这有帮助!
发生的情况是,每当您的customComponent 触发StudyEvent.STUDYSELECTED 事件时,您的主函数都会捕获该事件,并调用studySelectedListener。
I think it might be better for studyId to refer to the dataGrid rather than the dataGrid referring to studyId. You can add this to your main mxml:
This should work because TextArea.text will respond to the property changed event of DataGrid.selectedItem, so it will change whenever the selection changes.
EDIT: Dispatching events:
You can dispatch an event from any place in your code, and listeners will be able to listen in to that event. Eg:
Now you can listen for that event:
Hope this helps!
What happens is whenever a StudyEvent.STUDYSELECTED event is fired from your customComponent, it will be caught by your main function and studySelectedListener will be called.