ItemRenderer Flex 值未根据 ArrayCollection Provider 进行渲染

发布于 2024-10-16 09:03:56 字数 1470 浏览 2 评论 0原文

我在使用 itemRenderer 功能时遇到问题。当使用 ArrayCollection 时,使用 itemRenderer 的 DataGrid 中的可见数据将被渲染得很好。但如果我开始滚动,条目将在使用渲染器的单元格中重复。单元格未根据 id 填充日期。我在这里犯了什么错误。

我读了很多解释,例如:

http://blogs.adobe.com/ aharui/2007/03/thinking_about_item_renderers_1.html

这里是设置数据函数的代码(itemRenderer 正在扩展 HBox):

override public function set data(value:Object):void {
        _data = value;

        if(data!=null)
        {
            var maxValue:Number = 0;
            var maxFontHeight:int = 18;

            for each(var term:ArrayCollection in _data.story)
            {
                if((term.getItemAt(1) as Number)>maxValue)
                    maxValue=term.getItemAt(1) as Number;
            }

            for each(var term:ArrayCollection in _data.story)
            {
                var FontHeight:int = Math.floor((term.getItemAt(1) as Number) * maxFontHeight / maxValue);

                var l:Label = new Label();
                l.text = term.getItemAt(0) as String;
                l.setStyle("fontWeight","normal");
                l.setStyle("fontFamily","Verdana");
                l.setStyle("paddingRight",0);
                l.setStyle("paddingLeft",0);
                l.setStyle("fontSize", FontHeight);
                l.setStyle("color", 0x000000);

                this.addChild(l);

            }
        }
    }

i have a problem using the itemRenderer functionality. When using an ArrayCollection the visible Data in the DataGrid using the itemRenderer will be rendered just fine. But if i start scrolling the entries are repeating in the cells using the renderer. The cells are not filled with date according to the id. What mistake i'm doing here.

I read a lot of the explainations like:

http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html

here is the code for the set data function (itemRenderer is extending HBox):

override public function set data(value:Object):void {
        _data = value;

        if(data!=null)
        {
            var maxValue:Number = 0;
            var maxFontHeight:int = 18;

            for each(var term:ArrayCollection in _data.story)
            {
                if((term.getItemAt(1) as Number)>maxValue)
                    maxValue=term.getItemAt(1) as Number;
            }

            for each(var term:ArrayCollection in _data.story)
            {
                var FontHeight:int = Math.floor((term.getItemAt(1) as Number) * maxFontHeight / maxValue);

                var l:Label = new Label();
                l.text = term.getItemAt(0) as String;
                l.setStyle("fontWeight","normal");
                l.setStyle("fontFamily","Verdana");
                l.setStyle("paddingRight",0);
                l.setStyle("paddingLeft",0);
                l.setStyle("fontSize", FontHeight);
                l.setStyle("color", 0x000000);

                this.addChild(l);

            }
        }
    }

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

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

发布评论

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

评论(1

断爱 2024-10-23 09:03:56

在添加新内容之前,您并没有清除渲染器中已有的内容。

尝试将标签的构造移至 createChildren,在集合数据中设置文本(而不是构造另一个标签),并记住在数据为空时清除文本。

您还可以进行一些优化,例如在执行工作之前检查新数据与当前数据是否相同。

You aren't clearing down what's already there in the renderer before adding new stuff.

Try moving the construction of the label to createChildren, setting the text in set data (rather than constructing another label), and remembering to clear the text if the data is null.

There's a few more optimizations you could make such as checking the new data isn't the same as the current data before doing the work, for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文