2011-08-02 38 views

回答

3

的Flex(在我的理解)并不直接提供这个。你有几个选择。

无论使用哪种方式,您都可能需要将数据安排在分层模型中。 (家长有3个孩子似乎描述你的问题)

我看到的第一个选项将涉及到直接声明你的数据分层为advanceddatagrid。如果您搜索分层advanceddatagrid,您应该能够在线查找教程。

或者,您可能希望始终显示数据,而不仅仅是当您展开父项时。在这种情况下,您仍然需要分层模型,但您必须创建一个自定义的itemrenderer,以便能够代表一个父对象的所有子数据。 (一个在VBox/VGroup中有三个标签的itemrenderer可以用于你给出的例子)

如果这些没有帮助,或者你想要一个解决方案或其他解决方案的更多细节,请随时问一条评论。

编辑::

作为的itemRenderer的一个例子,这里是我使用了类似的itemRenderer的来源。 (矿山仅填充2个标签,但你应该能够扩展它,如果你知道它在做什么)

<VBox xmlns:mx="http://www.adobe.com/2006/mxml" 
    implements="mx.controls.listClasses.IDropInListItemRenderer" 
    width="100%" height="100%" 
    verticalGap="0" paddingTop="5" paddingBottom="5" 
    horizontalScrollPolicy="off" 
    horizontalAlign="center"> 

    <mx:Script> 
     <![CDATA[ 
      import mx.controls.Label; 
      import mx.controls.dataGridClasses.DataGridListData; 
      import mx.controls.listClasses.BaseListData; 

      private var _listData:BaseListData; 

      [Bindable("dataChange")] 

      // Define the getter method. 
      public function get listData():BaseListData 
      { 
       return _listData; 
      } 
      // Define the setter method, 
      public function set listData(value:BaseListData):void 
      { 
       _listData = value; 
      } 

     override public function set data(value:Object):void 
     { 
      removeAllChildren(); 

      if (value != null) 
      { 
       var myListData:DataGridListData = DataGridListData(listData); 

       var lLabel1:Label = new Label(); 
       var lLabel2:Label = new Label(); 


       lLabel1.text = value[myListData.dataField][0]; 
       lLabel1.percentWidth = 0; 
       addChild(lLabel1); 

       lLabel2.text = value[myListData.dataField][1]; 
       lLabel2.percentWidth = 0; 
       addChild(lLabel2); 
      } 

     } 
     ]]> 
    </mx:Script> 
</VBox> 

我删除了大量的专有代码,所以如果它没有任何意义,让我知道。

这意味着可以重复使用,因此值[myListData.dataField],但如果您想要,您可以通过自己定义字段轻松地使其更具体。这种特殊的代码期望在以下格式的数据,例如:

value[field][0] = "text1"; 
value[field][1] = "text2"; 

对象有:

var field:Array = []; 

field[0] = "text1"; 
field[1] = "text2"; 
+3

+1得到你需要的功能,唯一的办法是使用'AdvancedDataGrid '用'HierarcichalData'。 –

+0

建议是好的,但我需要在合并的单元格中显示一些垂直文本,我想知道在这种情况下是否可以使用itemRenderer。 –

+1

我附上了一些示例代码,@Mr。 G.让我知道这是否有帮助,或者如果你想多一点。 –