强制所有项目渲染器提交属性?

发布于 2024-08-24 14:42:00 字数 329 浏览 1 评论 0原文

我有一个项目渲染器,用于检查外部源的显示信息。如果该信息发生变化,我想强制所有项目渲染器实例检查它。

强制列表或网格中的所有项目渲染器 commitProperties 或执行其他方法的最佳方法是什么?

  • 我读过重置 grid.itemRenderer 属性将使 它们都初始化。

  • 我也收到了建议 递归地迭代所有 网格的子级并调用 invalidateProperties 在我找到的所有 UIComponents 上。

有什么想法吗?替代品?

I have an item renderer that checks an external source for display information. If that information changes, I want to force all item renderer instances to check it.

What's the best way for force all the item renderers in a list or grid to either commitProperties or execute some other method?

  • I've read that resetting the
    grid.itemRenderer property will make
    them all initialize.

  • I've also received the suggestion to
    iterate recursively through all the
    grid's children and call invalidateProperties
    on all the UIComponents I find.

Any thoughts? Alternatives?

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

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

发布评论

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

评论(3

别再吹冷风 2024-08-31 14:42:00

请记住,在 Flex Lists 中,您正在处理虚拟化和 itemRenderer 回收,因此通常只有当前可见的 itemRenderer 实际存在,因此才是实际需要更新的 itemRenderer。

以下适用于 Spark 基于列表的控件:

for ( var i:int=0; i< sparkList.dataGroup.numElements; i++ )
            {
                var element:UIComponent = sparkList.dataGroup.getElementAt( i ) as UIComponent;
                if ( element )
                    element.invalidateProperties();
                else
                    trace("element " + i.toString() + " wasn't there");

            }

如果您有 100 个项目,这将更新 10 个可见项目并忽略虚拟其余项目。

如果您正在使用 mx DataGrid,您可能想尝试它的变体 - 但它不使用 DataGroup / Spark 虚拟化,因此我无法立即为您提供答案。

PS 我正在对完全基于 Spark 的 DataGrid 进行最后的修饰,完成后我将发布链接。

Remember that in Flex Lists you're dealing with virtualization and itemRenderer recycling, so generally only the currently visible itemRenderers actually exist, and are therefore the ones that actually need updating.

The following works for Spark list-based controls:

for ( var i:int=0; i< sparkList.dataGroup.numElements; i++ )
            {
                var element:UIComponent = sparkList.dataGroup.getElementAt( i ) as UIComponent;
                if ( element )
                    element.invalidateProperties();
                else
                    trace("element " + i.toString() + " wasn't there");

            }

If you've got 100 items, this will update the 10 visible ones and ignore the virtual rest.

If you're working with mx DataGrid, you might want to try a variant of this- but it doesn't use DataGroup / Spark virtualization so I don't have an answer for you off the top of my head.

P.S. I'm putting the finishing touches on a completely Spark-based DataGrid, I'll post the link when I'm done.

梦晓ヶ微光ヅ倾城 2024-08-31 14:42:00

Datagroup 有 getItemIndicesInView() ,它将为您提供视图中所有项目渲染器的索引。使用这些索引调用 getElementAt。

我通常还扩展 ItemRenderer 并添加以下内容,这将导致项目渲染器的状态刷新。

   public function invalidateSkinState():void
   {
      super.invalidateRendererState();
   }

Datagroup has getItemIndicesInView() which will give you the indicies of all item renderers that are in view. Call getElementAt with those indicies.

I also usually extend ItemRenderer and add the following which will cause the item renderer's state to refresh.

   public function invalidateSkinState():void
   {
      super.invalidateRendererState();
   }
东北女汉子 2024-08-31 14:42:00
    public function updateAllRenderer():void
    {
        if (!list.dataGroup)
            return;
        if (!list.dataGroup.dataProvider)
            return;

        for ( var index:int=0; index< list.dataGroup.numElements; index++ )
        {
            var item:Object = list.dataGroup.dataProvider.getItemAt(index);
            var renderer:IVisualElement = list.dataGroup.getElementAt( index ) as IVisualElement;
            if ( renderer )
                list.updateRenderer( renderer, index, item );
        }
    }

对我来说效果很好

    public function updateAllRenderer():void
    {
        if (!list.dataGroup)
            return;
        if (!list.dataGroup.dataProvider)
            return;

        for ( var index:int=0; index< list.dataGroup.numElements; index++ )
        {
            var item:Object = list.dataGroup.dataProvider.getItemAt(index);
            var renderer:IVisualElement = list.dataGroup.getElementAt( index ) as IVisualElement;
            if ( renderer )
                list.updateRenderer( renderer, index, item );
        }
    }

works fine for me

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