5.1.创建可编辑的list组件

5.1.1 问题
创建一个所有条目都可以编辑的list 组件
5.1.2 解决方法
将list 组件的editable 属性设置为true 并侦听itemEditBegin 和itemEditEnd 属性.或通过包含columnIndex 和rowIndex 属性的对象来设置editedItemPosition。
5.1.3 讨论
所有的List 组件都可以通过简单地设置list 的editable 属性为true 使之可编辑。这就意味着每一个渲染都将变成一个由TextInput 模块控制和用户选择的itemRenderer 填充值的编辑器,List 类同样定义了一些当用户开始和结束修改正在编辑的值的时候用来通知应用程序的事件:

itemEditBegin:当editedItemPosition 属性已设置且项目可编辑后调度。当事件被触发,List组件使用createItemEditor 方法并且从编辑器拷贝data 属性来创建一个itemEditor 对象

itemEditBeginning:当用户准备好编辑项目(例如,在项目上释放鼠标按键)后调度,聚焦到列表或试图编辑列表

itemEditEnd:当项目编辑会话因任何原因而结束时调度。List 组件为这个拷贝自条目编辑器至list 组件的数据提供者的数据提供了一个默认的事件处理方式,默认情况下,List 组件使用editorDataField 属性来决定itemEditor 的属性包括新数据和使用新数据更新条目数据。

我们将在Chapter 7: "Renderers and Editors."中更加地详细讨论使用这些不同的事件并且控制由itemEditor 返回的数据

这个可编辑的条目可由用户点击List 中的一个itemRenderer 或设定List 组件的带有columnIndex 和rowIndex 属性的editedItemPosition 对象来设置, 在List 中,columnIndex 常常是0, 而rowIndex 则是编辑器将要创建的行的位置,例如:
+展开
-ActionScript
listImpl.editedItemPosition = {columnIndex:0, rowIndex:2};

完整例子如下:
+展开
-XML
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxmlwidth="400height="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" }]
//selectedItem属性返回用户在渲染器中做条目编辑后的没有再修改的值,
private function editEnd(event:Event):void {
trace (listImpl.selectedItem.foo+' ' +listImpl.selectedItem.name);
}
//在由rowIndex 和columnIndex 属性指示的位置设置editedItemPosition 创建编辑器 代码:
private function setEditor():void {
listImpl.editedItemPosition = {columnIndex:0, rowIndex:2};
}

]]>
</mx:Script>
<mx:Button click="setEditor()"/>
<mx:List y="30width="200selectedIndex="6id="listImplselectionColor="#CCCCFFlabelField="namedataProvider="{dp}editable="trueitemEditBegin="trace(listImpl.editedItemPosition)itemEditEnd="editEnd(event)editorXOffset="5"
editorYOffset="2"/>

</mx:Canvas>

加支付宝好友偷能量挖...


评论(0)网络
阅读(112)喜欢(0)flash/flex/fcs/AIR