带按钮的 Spark 列表 [英] Spark List with Buttons

查看:18
本文介绍了带按钮的 Spark 列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数据提供程序的 Spark 列表,其中包含已填写的表单应用程序列表.向每个列表项(表单应用程序)添加按钮的最佳方法是什么?此按钮将命名为打开",并将导航到指定的表单应用程序.

I have a Spark List with a data provider consisting of a list of filled out form applications. What is the best way to add a button to each List Item (form application)? This button will be named Open and will navigate to the specified form application.

提前感谢您的建议!

推荐答案

这与@www.Flextras.com 所说的类似,所以我不打算重复.不过,我会添加一个例子和一两件事.

This is similar to what @www.Flextras.com said, so I'm not going to repeat that. However, I'll add an example and one or two things.

您的自定义 ItemRenderer 可能如下所示:

Your custom ItemRenderer might look like this:

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark">

    <fx:Script>
        <![CDATA[
            import mx.events.ItemClickEvent;

            private function requestForm():void {
                var event:ItemClickEvent = new ItemClickEvent(ItemClickEvent.ITEM_CLICK);
                event.index = itemIndex;
                event.item = data;
                owner.dispatchEvent(event);
            }
        ]]>
    </fx:Script>

    <s:Label id="labelDisplay" verticalCenter="0" />
    <s:Button right="0" label="open" verticalCenter="0" click="requestForm()" />

</s:ItemRenderer>

与 Flextras 的回答不同的两点:

Two things that differ from Flextras' answer:

  • 我使用内置的 ItemClickEvent 而不是自定义事件 > 更少编码
  • 我在 ItemRenderer 的 owner 上分派事件,它实际上是包含此 ItemRenderer 的 List.因为这,您不需要冒泡事件.
  • I use the built-in ItemClickEvent instead of a custom event > less coding
  • I dispatch the event on the owner of the ItemRenderer, which is in fact the List that contains this ItemRenderer. Because of this, you don't need to bubble the Event.

现在要在单击按钮时打开表单,请执行以下操作:

Now to open the form when the Button is clicked, do something like this:

myList.addEventListener(ItemClickEvent.ITEM_CLICK, openForm);

private function openForm(event:ItemClickEvent):void {
    trace("open " + event.item.toString());
}

这篇关于带按钮的 Spark 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆