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 datagrid在一列中包含多个组件_Apache Flex_Flash_Actionscript 3_Datagrid - Fatal编程技术网

Apache flex datagrid在一列中包含多个组件

Apache flex datagrid在一列中包含多个组件,apache-flex,flash,actionscript-3,datagrid,Apache Flex,Flash,Actionscript 3,Datagrid,嗨,我想问一下,根据另一列的值,是否有可能在一列中同时包含字符串和单选按钮 |column1 | column 2 | |r | radiobutton| |s | string | 如果第1列中有一个r,则第2列中应显示一个单选按钮,否则第2列仅显示一个字符串 谢谢你的回答 Sebastian您需要编写自己的itemRenderer 从高层来看,您需要做的是告诉列您将按行呈现列。然后,每行-检查所需的条件(如查看不同的列或其他内容),并执行所需的操作(如

嗨,我想问一下,根据另一列的值,是否有可能在一列中同时包含字符串和单选按钮

|column1 | column 2   | 
|r       | radiobutton|
|s       | string     |
如果第1列中有一个r,则第2列中应显示一个单选按钮,否则第2列仅显示一个字符串

谢谢你的回答


Sebastian

您需要编写自己的itemRenderer

从高层来看,您需要做的是告诉列您将按行呈现列。然后,每行-检查所需的条件(如查看不同的列或其他内容),并执行所需的操作(如添加单选按钮或其他组件)

在“数据”列中,执行以下操作:

<mx:DataGridColumn id="yourColumn" 
headerText="Cool Column" editable="false" itemRenderer="SpecialCanvas"/>

您确实需要编写一个项目渲染器来执行此操作。但是,您希望在设置“数据”属性时更新渲染的状态。这很重要,因为项目渲染器是回收的。基本上,只要渲染器的数据发生更改,就会设置data属性,这在滚动DataGrid时发生

下面是一个带有DataGrid的简单应用程序:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete()">

<mx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;

        [Bindable] private var collection:ArrayCollection;

        private function onCreationComplete():void
        {
            collection = new ArrayCollection();
            for (var i:uint = 0; i < 20; i++)
                collection.addItem({name:'Person #'+i});
        }

    ]]>
</mx:Script>

<mx:DataGrid width="600" dataProvider="{collection}" rowCount="5">
    <mx:columns>
        <mx:DataGridColumn itemRenderer="com.foo.ItemRenderer"/>
    </mx:columns>
</mx:DataGrid>

</mx:Application>

和一个简单的基于MXML的渲染器:

<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
    <![CDATA[

        override public function set data(value:Object):void
        {
            super.data = value;
            // only show radio buttons if the "name" property of the data contains "5"; otherwise show a label
            radioS.visible = radioS.includeInLayout = radioM.visible = radioM.includeInLayout = radioL.visible = radioL.includeInLayout = data.name.indexOf(5) > -1;
            labelName.visible = labelName.includeInLayout = data.name.indexOf(5) < 0;               
        }

    ]]>
</mx:Script>

<mx:Label id="labelName" text="{data.name}"/>
<mx:RadioButton id="radioS" label="Small" groupName="radioGroup"/>
<mx:RadioButton id="radioM" label="Medium" groupName="radioGroup"/>
<mx:RadioButton id="radioL" label="Large" groupName="radioGroup"/>

</mx:HBox>

-1;
labelName.visible=labelName.includeInLayout=data.name.indexOf(5)<0;
}
]]>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
    <![CDATA[

        override public function set data(value:Object):void
        {
            super.data = value;
            // only show radio buttons if the "name" property of the data contains "5"; otherwise show a label
            radioS.visible = radioS.includeInLayout = radioM.visible = radioM.includeInLayout = radioL.visible = radioL.includeInLayout = data.name.indexOf(5) > -1;
            labelName.visible = labelName.includeInLayout = data.name.indexOf(5) < 0;               
        }

    ]]>
</mx:Script>

<mx:Label id="labelName" text="{data.name}"/>
<mx:RadioButton id="radioS" label="Small" groupName="radioGroup"/>
<mx:RadioButton id="radioM" label="Medium" groupName="radioGroup"/>
<mx:RadioButton id="radioL" label="Large" groupName="radioGroup"/>

</mx:HBox>