0

如何在自定义 itemrenderer 中访问/传递值对象?项目渲染器代表我的数据网格中的一个字段,我希望能够从我的 VO 访问属性。

谢谢

4

2 回答 2

1

您将需要覆盖项目渲染器的 set data 方法:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo">
    <fx:Script>
        <![CDATA[

            //Strongly typed VO for use in binding.
            [Bindable]
            private var myValueObject:MyValueObject;

            override public function set data(value:Object) : void
            {
                //we don't want to update if the value is the exact same.
                if(data === value)
                    return;

                //you could simply access the data property but I think
                //it is nicer to have strong typing for code hints
                super.data = myValueObject = value;
                validateNow();
            }
        ]]>
    </fx:Script>
    <mx:Label text="{myValueObject.name}"/>
</mx:Canvas>
于 2009-09-07T23:31:27.940 回答
0

这种方法怎么样?

项目渲染器 ItemRendererLink.mxml:

            public function goTo():void {
                Alert.show(goToScreen + " " + data.item_num);
            }
        ]]>
    </mx:Script>
</mx:LinkButton>

父组件:

    <mx:DataGridColumn dataField="item_num"
        headerText="Item #">
        <mx:itemRenderer>
            <mx:Component>
                <e:ItemRendererLink goToScreen="item"/>
            </mx:Component>
        </mx:itemRenderer>
    </mx:DataGridColumn>
于 2009-12-09T21:12:14.790 回答