Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 如何更改组件';在项目渲染器中动态设置属性?_Apache Flex_Datagrid_Flex4_Itemrenderer - Fatal编程技术网

Apache flex 如何更改组件';在项目渲染器中动态设置属性?

Apache flex 如何更改组件';在项目渲染器中动态设置属性?,apache-flex,datagrid,flex4,itemrenderer,Apache Flex,Datagrid,Flex4,Itemrenderer,我有一个包含形状对象数组的数据网格表。我的数据网格表中的GridColumn调用一个名为“MovementLogItemRenderer”的项目渲染器 在我的“MovementLogItemRenderer”中,我有一个包含少量标签的HGroup。我使用itemRenderer的data属性访问要在标签中显示的某些信息 我想做的是控制标签中文本的颜色。因此,当data.shapeColor的值等于“紫色”时,我想更改特定标签中文本的颜色 当我运行该文件时,它不会显示任何内容。整个UI不会显示在浏

我有一个包含形状对象数组的数据网格表。我的数据网格表中的GridColumn调用一个名为“MovementLogItemRenderer”的项目渲染器

在我的“MovementLogItemRenderer”中,我有一个包含少量标签的HGroup。我使用itemRenderer的data属性访问要在标签中显示的某些信息

我想做的是控制标签中文本的颜色。因此,当data.shapeColor的值等于“紫色”时,我想更改特定标签中文本的颜色

当我运行该文件时,它不会显示任何内容。整个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>


ActionScript中标签的颜色属性是uint
,因此必须使用此类型
(只有在MXML中才能使用颜色代码,如#000000)
由于要将ActionScript属性绑定到标签的颜色,因此必须使用uint类型
此外,如果itemRenderer将被重新循环,当条件不满足时,您必须将其设置回“正常”颜色。。
e、 g

为什么你的洞用户界面没有显示出来,没有更多的代码就无法告诉你
当我尝试使用网格组件时,您的示例运行良好

嗨,Micha Pooh..它仍然不起作用。用户界面仍然没有显示。。我做了一个MXML文件,其中只包含要测试的dataGrid。我更新了上面的代码。请看一看。我做错了什么??您好,我刚刚在prepare方法中添加了一个if(数据)检查-(参见上面更新的代码)-您的示例对我很有用-您在执行项目时是否有运行时错误?非常感谢!!!:)成功了!:)不,我的项目中没有运行时错误。
override public function prepare(hasBeenRecycled:Boolean):void {

            super.prepare( hasBeenRecycled );

            if(data) {
                if(data.shapeColor == "purple"){
                    myTextColour = 0x7a11f1;
                } else {
                    myTextColour = 0x000000;
                }
            }
        }