数据网格中数据提供程序的嵌套对象,不显示数据

时间:2011-05-19 12:15:20

标签: flex datagrid flex4 nested-datalist

我有一个数据网格,这个网格的数据提供者是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等)是动态的。我如何包含这些?

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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