Flex-----创建可编辑的List 组件

所有的List 组件都可以通过简单地设置list 的editable 属性为true 使之可编辑。这就意
味着每一个渲染都将变成一个由TextInput 模块控制和用户选择的itemRenderer 填充值的
编辑器,List 类同样定义了一些当用户开始和结束修改正在编辑的值的时候用来通知应用程
序的事件:
itemEditBegin:当editedItemPosition 属性已设置且项目可编辑后调度。当事件被触发,List组件使用createItemEditor 方法并且从编辑器拷贝data 属性来创建一个itemEditor 对象
itemEditBeginning:当用户准备好编辑项目(例如,在项目上释放鼠标按键)后调度,聚
焦到列表或试图编辑列表
itemEditEnd:当项目编辑会话因任何原因而结束时调度。List 组件为这个拷贝自条目编辑
器至list 组件的数据提供者的数据提供了一个默认的事件处理方式,默认情况下,List 组件
使用editorDataField 属性来决定itemEditor 的属性包括新数据和使用新数据更新条目数
据。
Java代码 复制代码
  1. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  
  2. layout="absolute">   
  3. <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400"  
  4. height="300">   
  5. <mx:Script>   
  6.     <![CDATA[   
  7.     [Bindable]   
  8.     private var dp:Array = [{name:"John Smith", foo:"bar"},   
  9.         {name:"Ellen Smith", foo:"baz"},   
  10.         {name:"James Smith", foo:"eggs"},   
  11.         {name:"Jane Smith", foo:"spam"}]   
  12.     private function editEnd(event:Event):void {   
  13.         trace(listImpl.selectedItem.foo+''+listImpl.selectedItem.name);   
  14.     }   
  15.     private function setEditor():void {   
  16.         listImpl.editedItemPosition = {columnIndex:0,   
  17.         rowIndex:3};   
  18.     }   
  19.     ]]>   
  20. </mx:Script>   
  21. <mx:Button click="setEditor()"/>   
  22. <mx:List y="30" width="200" selectedIndex="6" id="listImpl"  
  23.     selectionColor="#CCCCFF" labelField="name"  
  24.     dataProvider="{dp}"    
  25.     editable="true"  
  26.     itemEditBegin="trace(listImpl.editedItemPosition)"  
  27.     itemEditEnd="editEnd(event)" editorXOffset="5"  
  28.     editorYOffset="2"/>   
  29. </mx:Canvas>   
  30. </mx:Application>  
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400"
height="300">
<mx:Script>
	<![CDATA[
	[Bindable]
	private var dp:Array = [{name:"John Smith", foo:"bar"},
		{name:"Ellen Smith", foo:"baz"},
		{name:"James Smith", foo:"eggs"},
		{name:"Jane Smith", foo:"spam"}]
	private function editEnd(event:Event):void {
		trace(listImpl.selectedItem.foo+''+listImpl.selectedItem.name);
	}
	private function setEditor():void {
		listImpl.editedItemPosition = {columnIndex:0,
		rowIndex:3};
	}
	]]>
</mx:Script>
<mx:Button click="setEditor()"/>
<mx:List y="30" width="200" selectedIndex="6" id="listImpl"
	selectionColor="#CCCCFF" labelField="name"
	dataProvider="{dp}" 
	editable="true"
	itemEditBegin="trace(listImpl.editedItemPosition)"
	itemEditEnd="editEnd(event)" editorXOffset="5"
	editorYOffset="2"/>
</mx:Canvas>
</mx:Application>

listImpl.editedItemPosition = {columnIndex:0,
rowIndex:3};
选择第一列第四个

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值