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 等)是动态的。我如何包括那些?

4

2 回答 2

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>
于 2011-05-24T06:46:08.450 回答
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
于 2011-05-19T12:22:54.137 回答