2011-05-19 50 views
1

我有一個數據網格,並且此網格的數據提供者是RPC調用的結果。結果集具有以下結構:數據網格中的數據提供者的嵌套對象,不顯示數據

Array 
[0]->Object #1 
     [one] => 1 
     [two] => 1 
     [three] => Object #2 
      [apple1] = > Object #3 
       [color] => red 
       [rate] => 20 
      [apple2] => Object #4 (the number of apples is dynamic, apple3,apple4 .. and so on) 
       [color] => blue 
       [rate] => 100 

等等...所以蘋果對象的數量會因其動態變化而變化。如何在數據網格中顯示這些數據?

我看到了打造「嵌套的DataGridColumn」類的文章很多......這樣的:

http://active.tutsplus.com/tutorials/flex/working-with-the-flex-datagrid-and-nested-data-structures/

有幫助,但我的數據的問題是,一些指標(如apple1, apple2等)是動態的。我如何包括這些?

+0

你可以做的是生成的DataGridColumn動態ActionScript中,而不是在MXML http://milanl.blogspot.com/2009/06/dynamic-columns-in定義它們-datagrid-in-flex.html – JabbyPanda 2011-05-20 20:31:22

回答

0

您使用的是哪種服務器端技術? BlazeDs/amfphp,別的?

你應該做的是把你的蘋果包裝在ArrayCollection中,然後你應該沒問題。

[0]->RPC Result 
[one] => 1 
[two] => 1 
[three] => ArrayCollection 
    [1] = > Apple#3 
      [color] => red 
      [rate] => 20 
    [2] => Apple #4 (the number of apples is dynamic, apple3,apple4 .. and so on) 
      [color] => blue 
      [rate] => 100 
+0

我正在使用amfPHP ..我嘗試過......我放下了所有的對象並將所有的蘋果包裹在一個數組中......但沒有結果。另外,我的Flex應用程序是一個桌面應用程序(如果有問題)。爲了看看發生了什麼,我放棄了所有嵌套數組,並使用了簡單的一維數組。似乎也沒有得到顯示。我不知道我做錯了什麼。數據字段標籤等都是正確的。我甚至調試過,並在即時通訊中獲得結果。這是怎麼回事 ? – Lin 2011-05-19 13:54:28

1

我得到了這個工作。

我使用了內聯項目渲染器,並使用foreach循環遍歷包含動態嵌套對象的對象。這是我的代碼:

<mx:DataGridColumn headerText="Roles Assigned"> 
<mx:itemRenderer> 
<fx:Component> 
    <mx:VBox creationComplete="box1_creationCompleteHandler()"> 
    <fx:Script> 
    <![CDATA[ 
     import com.pm.modules.events.UpdateDBEvent;  
     import mx.containers.HBox; 
     import mx.controls.Alert; 
     import mx.controls.Label; 
     import mx.controls.LinkButton; 
     import mx.events.FlexEvent;  

     protected function box1_creationCompleteHandler():void 
     { 
     for each(var temp:Object in data.roles){ 
      var hgrp:HBox = new HBox(); 
      hgrp.autoLayout = false; 
      var lbl:Label = new Label(); 
      lbl.text = temp.rname; 
      var lb:LinkButton = new LinkButton(); 
      lb.label = 'X'; 
      lb.id = temp.rid.toString(); 
      lb.focusEnabled = true; 
      lb.addEventListener(MouseEvent.CLICK,handleClick); 

      hgrp.addElement(lbl); 
      hgrp.addElement(lb); 
      this.addElement(hgrp); 
     } 
    } 

    protected function handleClick(event:MouseEvent):void{ 
     dispatchEvent(new UpdateDBEvent(UpdateDBEvent.ON_DELETE_PRIVILEGE_ROLE_MAP,0,0,0,event.target.id,0,true)); 
    } 
]]> 
</fx:Script> 
</mx:VBox> 
</fx:Component></mx:itemRenderer></mx:DataGridColumn>