2011-05-19 26 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> 
相关问题