Spark List 是否支持 IDropInItemRenderer 接口?

发布于 2024-10-09 13:46:07 字数 344 浏览 8 评论 0原文

看来新的 Spark List 组件不支持 IDropInItemRenderer 接口。

即 - 如果我在渲染器上实现 IDropInItemRenderer,则永远不会调用 listData 的设置器。

我是否遗漏了什么,或者这个界面现在已被弃用?

如果是这样,向渲染器提供类似 dataProvider 上下文信息的建议方法是什么?

例如,我希望集合中最后一项的渲染器的行为略有不同。

我看到 IItemRenderer 现在定义了一个 listIndex 属性,但是如果不知道源 dataProvider 的计数,这种方法就不起作用。

It appears as though the new spark List component does not honour the IDropInItemRenderer interface.

Ie - if I implement IDropInItemRenderer on my renderer, the setter of listData is never called.

Am I missing something, or is this interface now deprecated?

If so, What is the suggested approach for providing similar dataProvider context information to the renderer?

For example, I want the renderer for the last item in a collection to behave slightly differently.

I see that IItemRenderer now defines a listIndex property, however this approach doesn't work without knowing the count of the source dataProvider.

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

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

发布评论

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

评论(2

静若繁花 2024-10-16 13:46:07

这是我最终使用的解决方法。

DataGroup 以它自己的方式体现了 Spark 的组合优势,因为它公开了 rendererUpdateDelegate 属性,您可以使用自己的类来设置该属性,以提供您想要的任何自定义功能。重新之后。

虽然令人沮丧的是,该界面在没有真正宣传的情况下就被删除了,但这种方法更强大。

这是一个示例类。在我的示例中,我希望最后一个渲染器的 collapsable 属性设置为 false

/**
 * Decorates another IItemRendererOwner (eg., a DataGroup) and augments the updateRenderer method
 * to set the isCollapsable property */
public class ThreadMessageRendererUpdateDelegate implements IItemRendererOwner
{
    private var _dataGroup:DataGroup;

    public function get dataGroup():DataGroup
    {
        return _dataGroup;
    }

    public function set dataGroup(value:DataGroup):void
    {
        _dataGroup = value;
        if (dataGroup)
        {
            dataGroup.rendererUpdateDelegate = this;
        }
    }


    public var dataProvider:ArrayCollection;

    public function ThreadMessageRendererUpdateDelegate(owner:DataGroup=null)
    {
        this.dataGroup = owner;
    }

    public function itemToLabel(item:Object):String
    {
        return dataGroup.itemToLabel(item);
    }

    public function updateRenderer(renderer:IVisualElement, itemIndex:int, data:Object):void
    {
        dataGroup.updateRenderer(renderer,itemIndex,data);
        if (renderer is ThreadMessageRenderer)
        {
            ThreadMessageRenderer(renderer).collapsable = itemIndex < dataProvider.length - 1;
        }
    }
}

这是示例用法:

<fx:Declarations>
    <viewer:ThreadMessageRendererUpdateDelegate dataProvider="{dataProvider}" dataGroup="{threadList}" />
</fx:Declarations>
<fx:Script>
    <![CDATA[
        [Bindable]
        public var dataProvider:ArrayCollection
    ]]>
</fx:Script>
    <s:DataGroup height="100%"
                 width="100%"
                 dataProvider="{dataProvider}"
                 itemRenderer="ThreadMessageRenderer"
                 id="threadList"
                 >
    </s:DataGroup>

Here's the workaround I've ended up using.

In it's own way, the DataGroup is dripping Spark's compositional goodness, in that it exposes a rendererUpdateDelegate property, which you can set with your own class to provide whatever custom functionliaty you're after.

While it's frustrating that the interface got dropped without really being advertised, this approach is much more powerful.

Here's an example class. In my example, I want the last renderer to have it's collapsable property set to false:

/**
 * Decorates another IItemRendererOwner (eg., a DataGroup) and augments the updateRenderer method
 * to set the isCollapsable property */
public class ThreadMessageRendererUpdateDelegate implements IItemRendererOwner
{
    private var _dataGroup:DataGroup;

    public function get dataGroup():DataGroup
    {
        return _dataGroup;
    }

    public function set dataGroup(value:DataGroup):void
    {
        _dataGroup = value;
        if (dataGroup)
        {
            dataGroup.rendererUpdateDelegate = this;
        }
    }


    public var dataProvider:ArrayCollection;

    public function ThreadMessageRendererUpdateDelegate(owner:DataGroup=null)
    {
        this.dataGroup = owner;
    }

    public function itemToLabel(item:Object):String
    {
        return dataGroup.itemToLabel(item);
    }

    public function updateRenderer(renderer:IVisualElement, itemIndex:int, data:Object):void
    {
        dataGroup.updateRenderer(renderer,itemIndex,data);
        if (renderer is ThreadMessageRenderer)
        {
            ThreadMessageRenderer(renderer).collapsable = itemIndex < dataProvider.length - 1;
        }
    }
}

And here's it's example usage:

<fx:Declarations>
    <viewer:ThreadMessageRendererUpdateDelegate dataProvider="{dataProvider}" dataGroup="{threadList}" />
</fx:Declarations>
<fx:Script>
    <![CDATA[
        [Bindable]
        public var dataProvider:ArrayCollection
    ]]>
</fx:Script>
    <s:DataGroup height="100%"
                 width="100%"
                 dataProvider="{dataProvider}"
                 itemRenderer="ThreadMessageRenderer"
                 id="threadList"
                 >
    </s:DataGroup>
木落 2024-10-16 13:46:07

男人!只是花了很长时间试图找到 DataGroup.rendererUpdateDelegate(...),最终发现为什么我找不到,感谢这篇 SO 帖子。

不管怎样,考虑一下 rendererUpdateDelegate 属性(消失)和你提供的更多一点,我意识到这两者都不是真正必要的。

DataGroup 具有 rendererAdd 事件,它可以在正确的时间为您提供足够的信息来执行您想要的操作;例如:

...

<s:DataGroup id="dg"
    dataProvider="{model.dataProvider}"
    itemRenderer="{model.itemRendererFactory}"
    rendererAdd="model.updateRenderer(event.data, event.index, event.renderer)">

...

...在 model 中,我们有:

public function updateRenderer(data:Object, index:int, renderer:IVisualElement):void
{
    if (renderer is ICollapsable)
    {
        ICollapsable(renderer).collapse = index < dataProvider.length - 1;
    }
}

更少的代码行和更清晰的意图

Man! Just spent ages trying to find DataGroup.rendererUpdateDelegate(...), eventually discovering why I couldn't, courtesy of this SO post.

Anyway, thinking about the (disappearance of) rendererUpdateDelegate property and your offering a little bit more, I realise neither are really necessary.

DataGroup has the rendererAdd event which gives you enough info, at the right time, to do what you want; for example:

...

<s:DataGroup id="dg"
    dataProvider="{model.dataProvider}"
    itemRenderer="{model.itemRendererFactory}"
    rendererAdd="model.updateRenderer(event.data, event.index, event.renderer)">

...

...and in the model we have:

public function updateRenderer(data:Object, index:int, renderer:IVisualElement):void
{
    if (renderer is ICollapsable)
    {
        ICollapsable(renderer).collapse = index < dataProvider.length - 1;
    }
}

Fewer lines of code and clearer intent

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