Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
803 views
in Technique[技术] by (71.8m points)

apache flex - Spark List with Buttons

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.

Thanks in advance for any advice!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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>

Two things that differ from Flextras' answer:

  • 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());
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...