【发布时间】:2011-11-03 16:06:16
【问题描述】:
我正在使用一个简单的 XML 文件填充我的数据网格的 3 列。最后一列应该是一个 itemrenderer,基本上是一个 Button。但是,该按钮应仅出现在数据网格的第 3 列的某些行上,具体取决于 XML 文件中的值,即“真”或“假”。所以基本上我想将 itemrenderer 中按钮的 Visible 属性设置为 true 或 false。
Here is the whole application
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" pageTitle="Dynamic Data Grid">
<!-- <s:layout>
<s:VerticalLayout horizontalAlign="center"/>
</s:layout>-->
<fx:Declarations>
<s:ArrayList id="cccb_dp">
<fx:String>User1</fx:String>
<fx:String>User2</fx:String>
<fx:String>User3</fx:String>
</s:ArrayList>
<fx:XML id="tempXML" source="assets/fieldsXML.xml"/>
<s:XMLListCollection id="fieldsXMLList" source="{tempXML.worker}"/>
</fx:Declarations>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:VGroup verticalAlign="middle" horizontalCenter="1" verticalCenter="1" horizontalAlign="center">
<s:HGroup horizontalAlign="center" verticalCenter="-221" width="580" height="158" x="75">
<s:Label text="CC" width="23" height="24" verticalAlign="middle" fontWeight="bold"/>
<s:DropDownList id="cc_cb" dataProvider="{cccb_dp}" width="175"/>
</s:HGroup>
<mx:DataGrid id="myDG" dataProvider="{fieldsXMLList}">
<mx:columns>
<mx:DataGridColumn headerText="Header1" dataField="@field_label"/>
<mx:DataGridColumn headerText="Header2" dataField="@field_value"/>
<mx:DataGridColumn headerText="Header3">
<mx:itemRenderer>
<fx:Component>
<s:Button click="onClick(event)" label="Click Me" dataChange="onDataChange(event)" >
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private function onClick(evt:Event):void
{
Alert.show(data.@field_visibility);
}
private function onDataChange(evt:Event):void
{
visible=data.@field_visibility;
}
]]>
</fx:Script>
</s:Button>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</s:VGroup>
</s:Application>
The XML:
<worker_fields>
<worker id="1" field_label="Seller" field_value="5" field_visibility="false"/>
<worker id="1" field_label="Balance" field_value="100" field_visibility="true"/>
<worker id="1" field_label="Cash Owned" field_value="300" field_visibility="true"/>
<worker id="2" field_label="Seller" field_value="5" field_visibility="false"/>
<worker id="2" field_label="Balance" field_value="130" field_visibility="true"/>
<worker id="2" field_label="Cash Owned" field_value="132" field_visibility="false"/>
<worker id="2" field_label="Credits" field_value="131" field_visibility="true"/>
</worker_fields>
Any idea how to go around it.
Thanks you for the precious help.
【问题讨论】:
标签: xml apache-flex datagrid flex4