Flex 3:如何在 ItemRenderer 中获取 DataGridColumn 的 dataField?

发布于 2024-09-15 10:15:22 字数 1927 浏览 5 评论 0原文

我正在尝试访问 itemRenderer 中 DataGridColumn 的 dataField。下面是 dataGrid:

<mx:Script>
    <![CDATA[
        [Bindable] public var weeksOfMoth:ArrayCollection = new ArrayCollection([
                {monday:30, tuesday:31, wednesday:1, thursday:2, friday:3, saturday:4, sunday:5},
                {monday:6, tuesday:7, wednesday:8, thursday:9, friday:10, saturday:11, sunday:12},
                {monday:13, tuesday:14, wednesday:15, thursday:16, friday:17, saturday:18, sunday:19}, 
                {monday:20, tuesday:21, wednesday:22, thursday:23, friday:24, saturday:25, sunday:26}, 
                {monday:27, tuesday:28, wednesday:29, thursday:30, friday:1, saturday:2, sunday:3}
            ]);
    ]]>
</mx:Script>
<mx:DataGrid dataProvider="{weeksOfMoth}" >
    <mx:columns>
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="monday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="tuesday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="wednesday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="thursday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="friday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="saturday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="sunday" />
    </mx:columns>
</mx:DataGrid>

这是我的 ItemRenderer:

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

                    <!-- How do I get the dataField here?? -->
        <mx:Label text="{data[dataField]}" /> 
    </mx:Box>
</mx:Canvas>

在 itemRenderer 的设置数据函数中,我收到了一整周(这没问题),但 itemRenderer 不知道要使用哪一天,因为 dataField 未知。有谁知道如何到达 itemRenderer 中的这个 dataField ?

I'm trying to reach the dataField of a DataGridColumn in the itemRenderer. Below is the dataGrid:

<mx:Script>
    <![CDATA[
        [Bindable] public var weeksOfMoth:ArrayCollection = new ArrayCollection([
                {monday:30, tuesday:31, wednesday:1, thursday:2, friday:3, saturday:4, sunday:5},
                {monday:6, tuesday:7, wednesday:8, thursday:9, friday:10, saturday:11, sunday:12},
                {monday:13, tuesday:14, wednesday:15, thursday:16, friday:17, saturday:18, sunday:19}, 
                {monday:20, tuesday:21, wednesday:22, thursday:23, friday:24, saturday:25, sunday:26}, 
                {monday:27, tuesday:28, wednesday:29, thursday:30, friday:1, saturday:2, sunday:3}
            ]);
    ]]>
</mx:Script>
<mx:DataGrid dataProvider="{weeksOfMoth}" >
    <mx:columns>
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="monday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="tuesday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="wednesday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="thursday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="friday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="saturday" />
        <mx:DataGridColumn itemRenderer="view.DateRenderer" dataField="sunday" />
    </mx:columns>
</mx:DataGrid>

And this is my ItemRenderer:

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

                    <!-- How do I get the dataField here?? -->
        <mx:Label text="{data[dataField]}" /> 
    </mx:Box>
</mx:Canvas>

In the set data function of the itemRenderer, I receive an entire week (which is ok), but the itemRenderer doesn't know which day to use because the dataField is unknown. Does anyone know how to reach this dataField in the itemRenderer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

蓦然回首 2024-09-22 10:15:22

www.Flextras.com 的评论帮助我找到了解决方案。我确实可以使用 listData.dataField,但首先需要实现 IDropInListItemRenderer 类。

最终的ItemRenderer:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.controls.listClasses.IDropInListItemRenderer" >
    <mx:Script>
        <![CDATA[
            import mx.controls.dataGridClasses.DataGridListData;
            import mx.controls.listClasses.BaseListData;


            // Internal variable for the property value.
            private var _listData:DataGridListData;

            // Make the listData property bindable.
            [Bindable("dataChange")]

            // Define the getter method.
            public function get listData():BaseListData
            {
              return _listData;
            }

            // Define the setter method,
            public function set listData(value:BaseListData):void
            {
              _listData = DataGridListData(value);
            }

        ]]>
    </mx:Script>
    <mx:Box width="80%" height="80%" verticalCenter="0" horizontalCenter="0" backgroundColor="#FFFFFF">
        <mx:Label text="{data[_listData.dataField]}" />
    </mx:Box>
</mx:Canvas>

The comment by www.Flextras.com helped me to find the solution. I can indeed use listData.dataField, but first the IDropInListItemRenderer class needs to be implemented.

The final ItemRenderer:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.controls.listClasses.IDropInListItemRenderer" >
    <mx:Script>
        <![CDATA[
            import mx.controls.dataGridClasses.DataGridListData;
            import mx.controls.listClasses.BaseListData;


            // Internal variable for the property value.
            private var _listData:DataGridListData;

            // Make the listData property bindable.
            [Bindable("dataChange")]

            // Define the getter method.
            public function get listData():BaseListData
            {
              return _listData;
            }

            // Define the setter method,
            public function set listData(value:BaseListData):void
            {
              _listData = DataGridListData(value);
            }

        ]]>
    </mx:Script>
    <mx:Box width="80%" height="80%" verticalCenter="0" horizontalCenter="0" backgroundColor="#FFFFFF">
        <mx:Label text="{data[_listData.dataField]}" />
    </mx:Box>
</mx:Canvas>
傲世九天 2024-09-22 10:15:22

使用 DataGridListData类,它被传递到渲染器中。它包含一个 dataField 属性。

我很确定这应该有效:

<mx:Label text="{data[listData.dataField]}" /> 

Use the DataGridListData class, which is passed into the renderer. It contains a dataField property.

I'm pretty sure this should work:

<mx:Label text="{data[listData.dataField]}" /> 
孤云独去闲 2024-09-22 10:15:22

您不必实现 IDropInListItemRenderer。
这就足够了:

data[ ( listData as DataGridListData ).dataField ]

具体的 listData 是 DataGridListData 类型,但属性本身的类型是 BaseListData,因为渲染器可以在各种场景中使用。但是,在这种情况下,我们知道它是 DataGridListData,因此我们可以简单地对其进行强制转换以访问 dataField 属性。

You don't have to implement the IDropInListItemRenderer.
This is enough:

data[ ( listData as DataGridListData ).dataField ]

The concrete listData is of type DataGridListData, but the property itself is typed to BaseListData, since a renderer can be used in various scenarios. However, in this scenario we know it's DataGridListData, therefore we can simply cast it to access the dataField property.

仅冇旳回忆 2024-09-22 10:15:22

以下适用于 MX AdvancedDataGrid 中基于 Spark 的项目渲染器:

<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                  xmlns:s="library://ns.adobe.com/flex/spark" 
                                  xmlns:mx="library://ns.adobe.com/flex/mx"
                                  width="100%"
                                  >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[               
            import mx.controls.dataGridClasses.DataGridListData;

            override public function set data( value:Object):void {             
                var latency:Number = value[ ( this.listData as DataGridListData).dataField] as Number;

                lbl.text = Utils.formatLatency( latency);
                if( latency > 1000000) { // 1s => error
                    lbl.setStyle( "backgroundColor", 0xFF8080);
                } else if( latency > 100000) { // 100ms => warning
                    lbl.setStyle( "backgroundColor", 0xFFFF80);
                } else if( latency > 0){ // low latency
                    lbl.setStyle( "backgroundColor", 0x80FF80);
                }
            }
        ]]>
    </fx:Script>
    <s:Label id="lbl" width="100%" height="100%" verticalAlign="middle" textAlign="right" paddingRight="5"/>
</s:MXAdvancedDataGridItemRenderer>

The following works for a Spark based item renderer in a MX AdvancedDataGrid:

<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                  xmlns:s="library://ns.adobe.com/flex/spark" 
                                  xmlns:mx="library://ns.adobe.com/flex/mx"
                                  width="100%"
                                  >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[               
            import mx.controls.dataGridClasses.DataGridListData;

            override public function set data( value:Object):void {             
                var latency:Number = value[ ( this.listData as DataGridListData).dataField] as Number;

                lbl.text = Utils.formatLatency( latency);
                if( latency > 1000000) { // 1s => error
                    lbl.setStyle( "backgroundColor", 0xFF8080);
                } else if( latency > 100000) { // 100ms => warning
                    lbl.setStyle( "backgroundColor", 0xFFFF80);
                } else if( latency > 0){ // low latency
                    lbl.setStyle( "backgroundColor", 0x80FF80);
                }
            }
        ]]>
    </fx:Script>
    <s:Label id="lbl" width="100%" height="100%" verticalAlign="middle" textAlign="right" paddingRight="5"/>
</s:MXAdvancedDataGridItemRenderer>
蹲在坟头点根烟 2024-09-22 10:15:22

更简单:
只需使用 MXAdvancedDataGridItemRenderers 中的属性

  • advancedDataGridListData

  • MXDataGridItemRenderer 中的 dataGridListData

    访问该信息。

Even simpler:
just use the properties

  • advancedDataGridListData in MXAdvancedDataGridItemRenderers

  • dataGridListDatain MXDataGridItemRenderer

    to access that information.

你的往事 2024-09-22 10:15:22

对于普通的 GridItemRenderer 来说,它是一个

column.dataField

所以,在你的情况下,这应该有效:

<s:Label text="{data[column.dataField]}" />

For an average GridItemRenderer it's a

column.dataField

So, in your case this should work:

<s:Label text="{data[column.dataField]}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文