flex问题。。。急
我想在此代码右侧的表格里加上修改删除详细的button,但是不知道怎么加,求高人帮助!!!
此页面都是静态的,暂不用动态生成。。。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
fontFamily="宋体"
fontSize="12">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import flash.geom.Point;
private var point1:Point=new Point();
// Open the TitleWindow container.
// Cast the return value of the createPopUp() method
// to SimpleTitleWindowExample, the name of the
// component containing the TitleWindow container.
private function showWindow():void
{
var login:SimpleTitleWindowExample=SimpleTitleWindowExample(PopUpManager.createPopUp(this, SimpleTitleWindowExample, true));
// Calculate position of TitleWindow in Application's coordinates.
point1.x=myButton1.x;
point1.y=myButton1.y;
point1=myButton1.localToGlobal(point1);
login.x=point1.x + 25;
login.y=point1.y + 25;
// Pass a reference to the TextInput control
// to the TitleWindow container so that the
// TitleWindow container can return data to the main application.
login.loginName=returnedName;
}
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import flash.geom.Point;
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
private var inited:Boolean=false;
[Bindable]
private var sList:Array;//可行
[Bindable]
private var uList:XMLList;
private function fullWindow():void{
//stage.nativeWindow.maximize();//与下面的效果想同,但作用不同
//stage.displayState= StageDisplayState.FULL_SCREEN;
inited=true;
}
[Bindable]
private var Cols:Array=["名称","数量","详细","修改","删除"];
[Bindable]
private var dgCols:XML= //这里还未实现绑定列标题
<Cols>
<Col>名称</Col>
<Col>数量</Col>
<Col>详细</Col>
<Col>修改</Col>
<Col>删除</Col>
</Cols>
private function get_Cols():String{
trace(dgCols.Col);
return dgCols.Col;
}
[Bindable]//dataProvider="{Members.Persions.Persion}" 可行
private var Members:XML=
<Members>
<Persions id="da001">
<Persion>
<name>鼠标</name>
<sex>1</sex>
<age>27</age>
<xx>27</xx>
<xg></xg>
<sc>27</sc>
</Persion>
<Persion>
<name>王</name>
<sex>sex2</sex>
<age>28</age>
</Persion>
</Persions>
<Persions id="ds001">
<Persion>
<name>李</name>
<sex>sex3</sex>
<age>29</age>
</Persion>
<Persion>
<name>赵</name>
<sex>sex4</sex>
<age>30</age>
</Persion>
</Persions>
</Members>
private var Persions:XML=
<Persions>
<Persion>
<name>Jone0</name>
<sex>mail</sex>
<age>20</age>
</Persion>
<Persion>
<name>Jone1</name>
<sex>mail</sex>
<age>20</age>
</Persion>
<Persion>
<name>Jone2</name>
<sex>mail</sex>
<age>20</age>
</Persion>
<Persion>
<name>Jone3</name>
<sex>mail</sex>
<age>20</age>
</Persion>
</Persions>
private function toUrl():void {
var urlstr : String = "tianjia.html";
navigateToURL(new URLRequest(urlstr),"_self");
}
private function getxml(e:Event):void{
//可行
var id:String=(Tree(e.currentTarget).selectedItem as XML).@d_ID;
trace(id);
if(id == "dc003")
uList=Persions.Persion;
else{
uList=Members.Persions.(@id==id).Persion;
}
//trace(uList);
}
private var companyData:XMLListCollection = new XMLListCollection(Members.department);
private function treeLabel(item:Object):String
{
var node:XML = XML(item);
if( node.localName() == "department" )
return node.@title;
else
return node.@name;
}
private function addEmployee():void
{
var newNode:XML = <employee/>;
newNode.@name = empName.text;
var dept:XMLList =Members.department.(@title == "Operations");
if( dept.length() > 0 ) {
dept[0].appendChild(newNode);
empName.text = "";
}
}
private function removeEmployee():void
{
var node:XML = XML(deTree.selectedItem);
if( node == null ) return;
if( node.localName() != "employee" ) return;
var children:XMLList = XMLList(node.parent()).children();
for(var i:Number=0; i < children.length(); i++) {
if( children[i].@name == node.@name ) {
delete children[i];
}
}
}
]]>
</mx:Script>
<mx:Panel title="TitleWindow Container"
layout="vertical"
color="0xffffff"
borderAlpha="0.15"
paddingTop="10"
paddingRight="10"
paddingBottom="10"
paddingLeft="10"
horizontalAlign="center">
<mx:Button id="myButton1"
color="0x323232"
height="32"
label="Click to open the TitleWindow container"
click="showWindow();"/>
<mx:Text id="returnedName"
width="100%"
color="0x323232"
text="Waiting..."/>
</mx:Panel>
<mx:XMLList id="deparement" >
<node title="部门列表" d_ID="d0000">
<node title="硬件通用" d_ID="da000">
<node title="财务一科" d_ID="da001"/>
</node>
<node title="服务器SVR" d_ID="ds000">
<node title="市场调研部" d_ID="ds001"/>
</node>
<node title="PC服务器" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
<node title="虚拟机" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
<node title="存储设备" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
<node title="SAN交换机" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
<node title="其他存储设备" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
</node>
</mx:XMLList>
<mx:MenuBar x="0" y="0" width="100%" height="25" id="MainMenu">
</mx:MenuBar>
<mx:Panel id="PanelHold" title="资产管理" layout="absolute" bottom="0" top="26" left="0" right="0">
<mx:constraintColumns>
<mx:ConstraintColumn id="Panel3_col1" width="0%"/>
<mx:ConstraintColumn id="Panel3_col2" width="100%"/>
</mx:constraintColumns>
<mx:HDividedBox x="163" y="156" width="100%" height="100%" left="0" top="0">
<mx:Tree height="100%" width="40%" id="deTree" dataProvider="{deparement}" labelField="@title" change="getxml(event)"></mx:Tree>
<mx:Button label="添加" labelPlacement="top" height="21" click="showWindow();" />
<mx:DataGrid height="100%" width="60%" id="userList" dataProvider="{uList}" fontStyle="normal" fontWeight="normal" textDecoration="none">
<mx:columns>
<mx:DataGridColumn headerText="名称" dataField="name"/>
<mx:DataGridColumn headerText="数量" dataField="sex"/>
<mx:DataGridColumn headerText="详细" dataField="age"/>
<mx:DataGridColumn headerText="修改" dataField="age"/>
<mx:DataGridColumn headerText="删除" dataField="age"/>
</mx:columns>
</mx:DataGrid>
</mx:HDividedBox>
</mx:Panel>
<mx:Button label="删除节点" click="removeEmployee()" x="246" y="-1"/>
<mx:Button label="添加节点" id="myButton" click="showWindow();" x="168" y="-1"/>
<mx:TextInput id="empName" x="0" y="0"/>
</mx:Application>
[解决办法]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
fontFamily="宋体"
fontSize="12">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import flash.geom.Point;
private var point1:Point=new Point();
// Open the TitleWindow container.
// Cast the return value of the createPopUp() method
// to SimpleTitleWindowExample, the name of the
// component containing the TitleWindow container.
//private function showWindow():void
//{
//var login:SimpleTitleWindowExample=SimpleTitleWindowExample(PopUpManager.createPopUp(this, SimpleTitleWindowExample, true));
//
//// Calculate position of TitleWindow in Application's coordinates.
//point1.x=myButton1.x;
//point1.y=myButton1.y;
//point1=myButton1.localToGlobal(point1);
//login.x=point1.x + 25;
//login.y=point1.y + 25;
//
//// Pass a reference to the TextInput control
//// to the TitleWindow container so that the
//// TitleWindow container can return data to the main application.
//login.loginName=returnedName;
//}
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import flash.geom.Point;
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
private var inited:Boolean=false;
[Bindable]
private var sList:Array;//可行
[Bindable]
private var uList:XMLList;
private function fullWindow():void{
//stage.nativeWindow.maximize();//与下面的效果想同,但作用不同
//stage.displayState= StageDisplayState.FULL_SCREEN;
inited=true;
}
[Bindable]
private var Cols:Array=["名称","数量","详细","修改","删除"];
[Bindable]
private var dgCols:XML= //这里还未实现绑定列标题
<Cols>
<Col>名称 </Col>
<Col>数量 </Col>
<Col>详细 </Col>
<Col>修改 </Col>
<Col>删除 </Col>
</Cols>
private function get_Cols():String{
trace(dgCols.Col);
return dgCols.Col;
}
[Bindable]//dataProvider="{Members.Persions.Persion}" 可行
private var Members:XML=
<Members>
<Persions id="da001">
<Persion>
<name>鼠标 </name>
<sex>1 </sex>
<age>27 </age>
<xx>27 </xx>
<xg> </xg>
<sc>27 </sc>
</Persion>
<Persion>
<name>王 </name>
<sex>sex2 </sex>
<age>28 </age>
</Persion>
</Persions>
<Persions id="ds001">
<Persion>
<name>李 </name>
<sex>sex3 </sex>
<age>29 </age>
</Persion>
<Persion>
<name>赵 </name>
<sex>sex4 </sex>
<age>30 </age>
</Persion>
</Persions>
</Members>
private var Persions:XML=
<Persions>
<Persion>
<name>Jone0 </name>
<sex>mail </sex>
<age>20 </age>
</Persion>
<Persion>
<name>Jone1 </name>
<sex>mail </sex>
<age>20 </age>
</Persion>
<Persion>
<name>Jone2 </name>
<sex>mail </sex>
<age>20 </age>
</Persion>
<Persion>
<name>Jone3 </name>
<sex>mail </sex>
<age>20 </age>
</Persion>
</Persions>
private function toUrl():void {
var urlstr : String = "tianjia.html";
navigateToURL(new URLRequest(urlstr),"_self");
}
private function getxml(e:Event):void{
//可行
var id:String=(Tree(e.currentTarget).selectedItem as XML).@d_ID;
trace(id);
if(id == "dc003")
uList=Persions.Persion;
else{
uList=Members.Persions.(@id==id).Persion;
}
//trace(uList);
}
private var companyData:XMLListCollection = new XMLListCollection(Members.department);
private function treeLabel(item:Object):String
{
var node:XML = XML(item);
if( node.localName() == "department" )
return node.@title;
else
return node.@name;
}
private function addEmployee():void
{
var newNode:XML = <employee/>;
newNode.@name = empName.text;
var dept:XMLList =Members.department.(@title == "Operations");
if( dept.length() > 0 ) {
dept[0].appendChild(newNode);
empName.text = "";
}
}
private function removeEmployee():void
{
var node:XML = XML(deTree.selectedItem);
if( node == null ) return;
if( node.localName() != "employee" ) return;
var children:XMLList = XMLList(node.parent()).children();
for(var i:Number=0; i < children.length(); i++) {
if( children[i].@name == node.@name ) {
delete children[i];
}
}
}
public function clickHanlder(obj:Object):void{
Alert.show(obj.toString());
}
]]>
</mx:Script>
<mx:Panel title="TitleWindow Container"
layout="vertical"
color="0xffffff"
borderAlpha="0.15"
paddingTop="10"
paddingRight="10"
paddingBottom="10"
paddingLeft="10"
horizontalAlign="center">
<mx:Button id="myButton1"
color="0x323232"
height="32"
label="Click to open the TitleWindow container"
/>
<!--click="showWindow();"-->
<mx:Text id="returnedName"
width="100%"
color="0x323232"
text="Waiting..."/>
</mx:Panel>
<mx:XMLList id="deparement" >
<node title="部门列表" d_ID="d0000">
<node title="硬件通用" d_ID="da000">
<node title="财务一科" d_ID="da001"/>
</node>
<node title="服务器SVR" d_ID="ds000">
<node title="市场调研部" d_ID="ds001"/>
</node>
<node title="PC服务器" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
<node title="虚拟机" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
<node title="存储设备" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
<node title="SAN交换机" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
<node title="其他存储设备" d_ID="dc000">
<node title="原料采购部" d_ID="dc001"/>
</node>
</node>
</mx:XMLList>
<mx:MenuBar x="0" y="0" width="100%" height="25" id="MainMenu">
</mx:MenuBar>
<mx:Panel id="PanelHold" title="资产管理" layout="absolute" bottom="0" top="26" left="0" right="0">
<mx:constraintColumns>
<mx:ConstraintColumn id="Panel3_col1" width="0%"/>
<mx:ConstraintColumn id="Panel3_col2" width="100%"/>
</mx:constraintColumns>
<mx:HDividedBox x="163" y="156" width="100%" height="100%" left="0" top="0">
<mx:Tree height="100%" width="40%" id="deTree" dataProvider="{deparement}" labelField="@title" change="getxml(event)"> </mx:Tree>
<mx:Button label="添加" labelPlacement="top" height="21" />
<!--click="showWindow();"-->
<mx:DataGrid height="100%" width="60%" id="userList" dataProvider="{uList}" fontStyle="normal" fontWeight="normal" textDecoration="none">
<mx:columns>
<mx:DataGridColumn headerText="名称" dataField="name"/>
<mx:DataGridColumn headerText="数量" dataField="sex"/>
<mx:DataGridColumn headerText="详细" dataField="age"/>
<mx:DataGridColumn headerText="修改" dataField="age">
<mx:itemRenderer>
<mx:Component>
<mx:Button label="aaaa" click="parentDocument.clickHanlder(data)"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="删除" dataField="age"/>
</mx:columns>
</mx:DataGrid>
</mx:HDividedBox>
</mx:Panel>
<mx:Button label="删除节点" click="removeEmployee()" x="246" y="-1"/>
<mx:Button label="添加节点" id="myButton" x="168" y="-1"/>
<!--click="showWindow();"-->
<mx:TextInput id="empName" x="0" y="0"/>
</mx:Application>
我修改一下,你单独在其他地方新建一个运行试试.
我这边能出来,不知理解你的意思了吗?