【问题标题】:How to display result of query to custom cell of DataGrid [Flex]如何将查询结果显示到 DataGrid 的自定义单元格 [Flex]
【发布时间】:2011-12-14 21:48:31
【问题描述】:
我按照本指南显示来自 mysql 数据库的数据:
http://www.flashrealtime.com/flash-builder-4-and-php-data-services/
但是如果我有这样的数据网格怎么办:
<mx:DataGrid id="dataGrid" width="100%" height="100%" creationComplete="dataGrid_creationCompleteHandler(event)" >
<mx:columns>
<mx:DataGridColumn id="something" dataField="customerId" editable="false">
<mx:itemRenderer >
<mx:Component>
<mx:VBox>
<mx:Label id="l1" text=??????? ></mx:Label>
<mx:Label id="l2" text=??????? ></mx:Label>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
【问题讨论】:
标签:
apache-flex
datagrid
mxml
【解决方案1】:
在 DataGrid 中使用 itemRenderer 时,整个“行”的值存储在“数据”对象中
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var dp:ArrayCollection = new ArrayCollection([
{id : "1", name : "Bob"},
{id : "2", name : "Andrew"},
{id : "3", name : "Paul"}
]);
]]>
</fx:Script>
<mx:DataGrid dataProvider="{dp}">
<mx:columns>
<mx:DataGridColumn>
<mx:itemRenderer>
<fx:Component>
<mx:VBox>
<mx:Label text="{data.id}"/>
<mx:Label text="{data.name}"/>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</s:WindowedApplication>