我正在尝试在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的set data函数中,我收到了整整一周的时间(可以),但是itemRenderer不知道要使用哪一天,因为dataField是未知的。有人知道如何在itemRenderer中到达此dataField吗?

最佳答案

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>

09-28 12:21