2009-12-17 67 views
0

返回Flex另一個問題。 我有一個XML結構是怎樣的?Flex + DataGrid +選擇上的動態顯示

<Student> 
    <Name>X</Name> 
    <Age>14</Age> 
</Student> 

<Student> 
    <Name>Y</Name> 
    <Age>16</Age> 
    <Address> 
    <HNumber>1</HNumber> 
    <HName>Something</HName> 
    <HPin>33607</HPin> 
    </Address> 
</Student> 

現在,我得到了他說的dataProvider =的XMLListCollection ...

我想要做的是一排,檢查的選擇,顯示在我的網格如果它有「地址」標籤,如果它有顯示其他網格,否則隱藏網格。 任何幫助!

回答

1
if(myDataGrid.selectedItem.hasownproperty("Address")){ 
    display other grid 
}else{ 
    hide other grid 
} 
+0

另一個問題在這裏,我將如何顯示只有選定的學生的地址?因爲如果我的結構有一個空的地址標記,那麼顯示的數據將是相同的?有什麼建議麼? – Vivek 2009-12-18 04:28:31

+0

你能改說或提供更多細節嗎?也許你的一些datagrid代碼? – invertedSpear 2009-12-18 15:26:03

0

要綁定/連接兩個網格你寫類似如下:

<mx:DataGrid id="grid1" width="100%" dataProvider="{data1}" > 
    <mx:columns> 
    <mx:DataGridColumn headerText="Name" dataField="@Name"/> 
    </mx:columns> 
</mx:DataGrid> 

<mx:DataGrid id="grid2" width="100%" > 
    <mx:columns> 
    <mx:DataGridColumn headerText="Name" dataField="@HNumber"/> 
    </mx:columns> 
</mx:DataGrid> 
    <mx:Binding source="grid1.selectedItem.Address" destination="grid2.dataProvider"/> 
</mx:Application> 

希望這會有所幫助。 xxx