grid主窗口与子窗口信息交互

前天写了双击GRID然后弹出子窗口,可交互信息的内容

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:title="*" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.controls.Alert;
import flash.events.MouseEvent;
import mx.events.CloseEvent;
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
import mx.managers.PopUpManager;

private var menuData:ArrayCollection= new ArrayCollection();
private var canvas:Sprite = new Sprite();
private var uiComponent:UIComponent;


/**
* 初始化蒙板等。
**/

private function init():void{
menuData=new ArrayCollection([
{no:"101",name:"菜单管理",address:"21",type:"branch"},
{no:"102",name:"查询测试",address:"22",type:"leaf"},
{no:"103",name:"更改",address:"23",type:"branch"}
]);

//初始化蒙板的颜色以及透明度
var g:Graphics = canvas.graphics;
g.beginFill(0x000000,0.3);
g.drawRect(0,0,this.width,this.height);
g.endFill();
menuDataGrid.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, doubleClick);
this.menuDataGrid.dataProvider=menuData;
}


/**
* 删除操作, 通过提示是否删除,通过事件来捕捉用户的操作.
**/
private function doDel():void{
if(menuDataGrid.selectedItem == null){
Alert.show("请选择需要删除的菜单");
}else{
Alert.show("确定删除?", "删除", 3, this, delClickHandler);
}

}

/**
*如果确认了删除,则将menuData中的记录删除
**/
private function delClickHandler(event:CloseEvent):void {
if (event.detail==Alert.YES){
menuData.removeItemAt(menuDataGrid.selectedIndex);
}
}

/**
* 双击操作,双击目前为编辑数据
**/
private function doubleClick(event:ListEvent):void{
doEdit();
}

/**
* 编辑操作
**/
private function doEdit():void{
if(menuDataGrid.selectedItem == null){
Alert.show("请选择需要编辑的菜单");
}else{
uiComponent= new UIComponent();
uiComponent.addChild(canvas);
this.addChild(uiComponent);
var menuWindow:MenuTitleWindow = new MenuTitleWindow();
var obj:Object= {selectIndex:menuDataGrid.selectedIndex,no:menuDataGrid.selectedItem.no,name:menuDataGrid.selectedItem.name,address:menuDataGrid.selectedItem.address
,type:menuDataGrid.selectedItem.type};
if(menuDataGrid.selectedItem.type == "branch"){
obj.typeSelIndex=0;
}else{
obj.typeSelIndex=1;
}
obj.editDo= editMenuData;
obj.cancleDo=cancleEdit;
menuWindow.object = obj;
PopUpManager.addPopUp(menuWindow,this);
PopUpManager.centerPopUp(menuWindow);
}
}
/**
*增加操作
**/
private function doAdd():void{
if(uiComponent == null){
uiComponent = new UIComponent();
uiComponent.addChild(canvas)
}
this.addChild(uiComponent);
var menuWindow:MenuTitleWindow = new MenuTitleWindow();
var object:Object = {editDo:editMenuData,cancleDo:cancleEdit};
menuWindow.object= object;
PopUpManager.addPopUp(menuWindow,this);
PopUpManager.centerPopUp(menuWindow);
}


/**
* 此将函数作为一个变量传递给子窗口,并且在子窗口中调用
* 目前如果是编辑,则能够得到grid的selectIndex,且已经够selectIndex传入子窗口中.
* 可以将selectIndex是否存在作为判断是更改菜单还是增加菜单.
**/
private function editMenuData(menuTitle:MenuTitleWindow):void{
var object:Object = menuTitle.resultObject;
if(object.hasOwnProperty("selectIndex")){
menuData.removeItemAt(object.selectIndex);
menuData.addItemAt(object,object.selectIndex);
}else{
menuData.addItem(object);
}
this.menuDataGrid.dataProvider=menuData;
this.cancleEdit();
}

/**
*移去蒙板
**/
private function cancleEdit():void{
this.removeChild(uiComponent);
}


]]>
</mx:Script>

<mx:DataGrid id="menuDataGrid" includeInLayout="true" visible="true" width="100%" height="90%"
editable="false" y="34" doubleClickEnabled="true" >
<mx:columns>
<mx:DataGridColumn dataField="no" headerText="编号" />
<mx:DataGridColumn dataField="name" headerText="名称"/>
<mx:DataGridColumn dataField="address" headerText="地址"/>
<mx:DataGridColumn dataField="type" headerText="类型" />
</mx:columns>
</mx:DataGrid>
<mx:Button id= "delButton" label="删除菜单" click="doDel()" x="10" y="10"/>
<mx:Button id= "editButton" label="编辑菜单" click="doEdit()" x="126" y="10"/>
<mx:Button id= "addButton" label="增加菜单" click="doAdd()" x="230" y="10"/>

</mx:Application>


<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" title="菜单" showCloseButton="false" alpha="1.0" fontFamily="Times New Roman" fontSize="12">

<mx:Script>
<![CDATA[
import mx.managers.FocusManager;
import mx.managers.PopUpManager;
import mx.collections.ArrayCollection;

[Bindable]
public var object:Object;

public var resultObject:Object;

private var saveData:Function;
private var cancleEdit:Function;

[Bindable]
public var types:ArrayCollection = new ArrayCollection(
[ {label:"branch", data:1},
{label:"leaf", data:2}]);



/**
* 弹出菜单保存以后,保存数据,主菜单中的保存方法是变量形式传递进来
* saveData对应的是 menu.mxml中的editMenuData(menuTitle:MenuTitleWindow).
* 将MenuTitleWindow.mxml作为参数传递回去,操作菜单中的结果集.
**/
private function doSave():void{
saveData = object.editDo;

if(object.hasOwnProperty("selectIndex")){
resultObject={no:this.no.text,name:this.menuName.text,
address:this.address.text,type: this.typeCombo.selectedItem.label,
selectIndex:object.selectIndex} ;
}else{
resultObject={no:this.no.text,name:this.menuName.text,
address:this.address.text,type: this.typeCombo.selectedItem.label};
}
this.saveData(this);
PopUpManager.removePopUp(this);
}
private function doCancle():void{
cancleEdit = object.cancleDo;
PopUpManager.removePopUp(this);
this.cancleEdit();
}
]]>
</mx:Script>
<mx:HBox width="100%" y="40">
<mx:Label text="No:" width="65" textAlign="left"/>
<mx:TextInput id="no" text="{object.no}" width="100%" textAlign="left"/>
</mx:HBox>
<mx:HBox width="100%" y="161">
<mx:Label text="菜单名称:" width="65"/>
<mx:TextInput id="menuName" text="{object.name}" width="100%" textAlign="left" />
</mx:HBox>
<mx:HBox width="100%" y="68">
<mx:Label text="地址:" width="65"/>
<mx:TextInput id="address" text="{object.address}" width="100%" textAlign="left"/>
</mx:HBox>
<mx:HBox width="100%" y="112">
<mx:Label text="类型:" width="65"/>
<mx:ComboBox id = "typeCombo" dataProvider="{types}" selectedIndex="{object.typeSelIndex}">
</mx:ComboBox>
</mx:HBox>
<mx:Button label="保存" click="doSave()" x="118" y="228"/>
<mx:Button label="关闭" click="doCancle()" x="201" y="228"/>
</mx:TitleWindow >


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值