我有一个包含形状对象数组的数据网格表。我的数据网格表中的 GridColumn 调用了一个名为“MovementLogItemRenderer”的项目渲染器。
在我的“MovementLogItemRenderer”中,我有一个包含几个标签的 HGroup。我使用 itemRenderer 的数据属性来访问要在标签中显示的某些信息。
我想要做的是控制标签中文本的颜色。因此,当 data.shapeColor 的值等于 "purple" 时,我想更改特定标签中文本的颜色。
当我运行该文件时,它没有向我显示任何内容。整个 UI 未显示在浏览器上。
请有人告诉我如何做到这一点?这样做的正确方法是什么?
这是我的包含数据网格表的 MXML 文件:
<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"
creationComplete="createShapes()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
private var myShapes:ArrayCollection = new ArrayCollection();
import FrontEndObjects.Shapes;
private function createShapes():void{
var shape1:Shapes = new Shapes();
shape1.shapeId = "1001";
shape1.shapeName ="Rec";
shape1.shapeColor ="pink";
var shape2:Shapes = new Shapes();
shape2.shapeId = "1002";
shape2.shapeName ="Cirl";
shape2.shapeColor ="orange";
var shape3:Shapes = new Shapes();
shape3.shapeId = "1003";
shape3.shapeName ="Trig";
shape3.shapeColor ="purple";
myShapes.addItem(shape1);
myShapes.addItem(shape2);
myShapes.addItem(shape3);
}
]]>
</fx:Script>
<s:DataGrid x="52" y="105" width="378" dataProvider="{myShapes}" requestedRowCount="4">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="shapedetails" headerText="Shape details" itemRenderer="FrontEndObjects.MovementLogItemRenderer"></s:GridColumn>
<s:GridColumn dataField="shapeId" headerText="Shape Id"></s:GridColumn>
<s:GridColumn dataField="shapeName" headerText="Shape Name"></s:GridColumn>
<s:GridColumn dataField="shapeColor" headerText="Shape Colour"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
这是我的“MovementLogItemRenderer”项目渲染器:
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
<fx:Script>
<![CDATA[
[Bindable] public var myTextColour:uint;
override public function prepare(hasBeenRecycled:Boolean):void {
super.prepare( hasBeenRecycled );
if(data.shapeColor == "purple"){
myTextColour = 0x7a11f1;
} else {
myTextColour = 0x000000;
}
}
]]>
</fx:Script>
<s:HGroup>
<s:Label text="{data.shapeId}" paddingTop="8"/>
<s:Label text="{data.shapeName}" paddingTop="8" />
<s:Label text="{data.shapeColor}" paddingTop="8" color="{myTextColour}" />
</s:HGroup>