我需要合并单元格,如图所示:
最佳答案
Flex(以我的理解)不直接提供这一点。你有几个选择。
无论哪种方式,您可能都需要在分层模型中排列数据。 (有 3 个 child 的家长似乎在描述您的问题)
我看到的第一个选项是直接将您的数据声明为高级数据网格的层次结构。如果您搜索分层高级数据网格,您应该能够在线找到教程。
或者,您可能希望始终显示数据,而不仅仅是在展开父项时。在这种情况下,您仍然需要分层模型,但您必须创建一个自定义 itemrenderer,能够表示一个父对象的所有子数据。 (在 VBox/VGroup 中带有三个标签的 itemrenderer 适用于您给出的示例)
如果这些没有帮助,或者您想了解有关一种或另一种解决方案的更多详细信息,请随时在评论中提问。
编辑::
作为 itemrenderer 的示例,这里是我使用过的类似 itemrenderer 的来源。 (我的只填充两个标签,但如果您了解它在做什么,您应该能够扩展它)
<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";
关于apache-flex - 如何在 Adobe Flex 中合并 DataGrid/AdvancedDataGrid 中的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6910625/