我有一个mxml组件,其中包含一个列出项目名称和代码版本的数据网格。我将所选项目从datagrid绑定到名为“selectedProjects”的公共变量。但是如何在另一个mxml组件中访问此变量。我希望在该组件的文本区域中选择项目的名称。怎么做? 我甚至创建了第一个组件的实例,并使用名为selectedProjects的变量。但我没有在文本区域中更新值。
这是我在变量中获取所选项目名称的第一个组件的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="handleCreationComplete();"
width="800" height="600">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.PopUpManager;
import mx.collections.ArrayCollection;
import mx.events.ItemClickEvent;
[Bindable] public var selectedProjects:Array;
private function handleCreationComplete():void {
PopUpManager.centerPopUp(this);
}
public var pages:ArrayCollection=new ArrayCollection([
{label:"10"},
{label:"20"},]);
public var projectList:ArrayCollection=new ArrayCollection([
{ItemName:"User Requirement Specification",ItemCodeVersion:"URS - 1"},
{ItemName:"User Requirement Specification",ItemCodeVersion:"URS - 2"},
{ItemName:"Software Requirement Specification",ItemCodeVersion:"SRS - 2.1"},
{ItemName:"Software Design Specification",ItemCodeVersion:"SDS - 2"},
{ItemName:"Software Design Specification",ItemCodeVersion:"SRS - 1.1"},
{ItemName:"User Manual",ItemCodeVersion:"User Manual - 1"},
{ItemName:"User Manual",ItemCodeVersion:"User Manual - 2.1"},]);
private function close():void
{
PopUpManager.removePopUp(this);
}
private function select():void
{
Alert.show(projectListDG.selectedItem.ItemName);
PopUpManager.removePopUp(this);
}
]]>
</mx:Script>
<mx:Binding source="projectListDG.selectedItems" destination="selectedProjects" />
<mx:Label styleName="labelHeading" text="Project Documents List"/>
<mx:Panel width="100%" height="100%" layout="vertical" title="Documents List" >
<mx:HBox>
<mx:Label text="Show"/>
<mx:ComboBox dataProvider="{pages}" width="60" />
<mx:Label text="results per page" />
</mx:HBox>
<mx:DataGrid id="projectListDG" dataProvider="{projectList}" allowMultipleSelection="true" rowCount="10" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="Select" itemRenderer="mx.controls.CheckBox" textAlign="center" width="50"/>
<mx:DataGridColumn headerText="Item Name" dataField="ItemName" textAlign="center" />
<mx:DataGridColumn headerText="Item Code - Version" dataField="ItemCodeVersion" textAlign="center" width="150 " />
</mx:columns>
</mx:DataGrid>
<mx:Label text="{projectListDG.selectedItem.ItemName}"/>
</mx:Panel>
<mx:HBox horizontalAlign="center" width="100%">
<mx:Button label="Select" click="select();"/>
<mx:Button label="Cancel" click="close();"/>
</mx:HBox>
</mx:TitleWindow>
我现在在selectedProjects变量中有所选项目。
现在这是我尝试使用项目名称的第二个组件。
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.core.IFlexDisplayObject;
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
[Bindable]
public var projectList:projDocsLookUp=new projDocsLookUp();
//Datagrid
[Bindable]
private var defectDetails:ArrayCollection = new ArrayCollection([
{Select:true},
]);
private function projDocsPopUp():void{
var helpWindow:TitleWindow = TitleWindow(PopUpManager.createPopUp(this, projDocsLookUp, true));
helpWindow.title="Project Documents List";
}
]]>
</mx:Script>
<mx:Label styleName="labelHeading" text="Defect Entry - Verification" />
<mx:Panel width="100%" height="30%" layout="vertical" title="Review Report Details">
<mx:VBox width="100%">
<mx:FormItem label="Project Name:" width="100%">
<mx:Text text="IPMS"/>
</mx:FormItem>
<mx:HRule width="100%"/>
<mx:VBox>
<mx:FormItem label="Project Documents:">
<mx:HBox>
<!--text="{projectList.projectListDG.selectedItem.ItemName}"-->
<mx:TextArea id="projDocs" width="150" text="{projectList.selectedProjects}" />//text area field is not updated.
<mx:Button width="30" label=".." click="projDocsPopUp();"/>
</mx:HBox>
</mx:FormItem>
</mx:VBox>
</mx:Panel>
<mx:Panel width="100%" height="50%" layout="vertical" title="Defect Details" >
<mx:DataGrid id="defectDG" dataProvider="{defectDetails}" variableRowHeight="true" width="100%" height="75" >
<mx:columns>
<mx:DataGridColumn dataField="Select" itemRenderer="mx.controls.CheckBox" width="50" textAlign="center" />
<mx:DataGridColumn dataField="Defect Id" itemRenderer="mx.controls.TextInput" textAlign="center"/>
<mx:DataGridColumn dataField="Status" itemRenderer="mx.controls.ComboBox" textAlign="center"/>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</mx:VBox>
我试图在Id“projDocs”的文本区域中更新所选项目的值,但我不明白..请有人帮助我..
答案 0 :(得分:1)
我自己找到了解决方案..
谷歌搜索当然。我按照这个tutorial.
中给出的方法我添加了对父应用程序的TextArea控件的引用。弹出组件使用该引用来更新第一个组件的TextArea。
在第一个组件中,我将创建弹出窗口的函数更改为
private function projDocsPopUp():void{
var helpWindow:projDocsLookUp = projDocsLookUp(PopUpManager.createPopUp(this, projDocsLookUp, true));
helpWindow.title="Project Documents List";
helpWindow.showCloseButton=true;
helpWindow.targetComponent=projDocs; //I get the value returned by the pop up window here
然后在弹出组件中,将select函数更改为:
private function select():void
{
var i:int;
for(i=0;i<selectedProjects.length;i++)
{
targetComponent.text+=selectedProjects[i].ItemName+",";
}
PopUpManager.removePopUp(this);
}
最后,我在第一个组件文本区域框中更新了项目名称。