2009-10-13 120 views
1

我有一个mxml组件,其中包含一个列出项目名称和代码版本的datagrid。我从datagrid绑定到名为“selectedProjects”的公共变量的选定项目。但是如何在另一个mxml组件中访问这个变量。我想在该组件的文本区域中选择项目的名称。怎么做? 我甚至创建了第一个组件的实例,并使用了名为selectedProjects变量的实例。但是我没有在文字区域更新价值。如何在Flex中将一个mxml组件的值数组传递给另一个mxml组件?

这是第一部分的代码,我在一个变量获得所选项目名称:

<?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

在您选择项目(在您的select()方法)后,您的TitleWindow是否会关闭?这不是说所选的项目名称不再可用,所以你无法在其他课程中阅读它吗? – 2009-10-14 04:28:54

+0

哦..我是新来的flex和刚刚学习它,因为我做我的项目。那么如何传递变量? – Angeline 2009-10-14 04:51:02

+0

即使在窗口关闭后,是否还有任何方法传递数据? – Angeline 2009-10-14 05:04:34

回答

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 

然后在弹出的组件的功能,改变了选择功能:

private function select():void 
     { 
      var i:int; 
      for(i=0;i<selectedProjects.length;i++) 
       { 
       targetComponent.text+=selectedProjects[i].ItemName+","; 
      } 


      PopUpManager.removePopUp(this); 
     } 

最后我在第一个组件文本区域框中更新项目名称。

相关问题