将值对象传递给 itemRenderer

发布于 2024-08-04 06:01:23 字数 85 浏览 2 评论 0原文

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

谢谢

how can access/pass a value object in a custom itemrenderer? The item renderer represents a field in my datagrid and i want to be able access properties from my VO.

Thanks

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

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

发布评论

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

评论(2

橘香 2024-08-11 06:01:23

您将需要重写项目渲染器的设置数据方法:

<?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>

You will want to override the set data method of the item renderer:

<?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>
不语却知心 2024-08-11 06:01:23

这种方法怎么样?

项目渲染器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>

What about this approach?

Item renderer ItemRendererLink.mxml:

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

parent component:

    <mx:DataGridColumn dataField="item_num"
        headerText="Item #">
        <mx:itemRenderer>
            <mx:Component>
                <e:ItemRendererLink goToScreen="item"/>
            </mx:Component>
        </mx:itemRenderer>
    </mx:DataGridColumn>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文