Candles with buttons

I have a Spark List with a data provider consisting of a list of completed form applications. What is the best way to add a button to each list item (form application)? This button will be called Open and go to the specified form application.

Thanks in advance for any advice!

+1
source share
2 answers

This is similar to what @ www.Flextras.com said, so I will not repeat it. However, I will 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 Flexstras' answer:

  • I use the built-in ItemClickEvent element instead of a custom event> less encoding
  • I am sending an event to the owner ItemRenderer, which is actually the list that this ItemRenderer contains. Because of this, you do not need to bubble an 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()); } 
+8
source

Use a custom itemRenderer element that displays a button along your itemRenderer data (form application).

At the push of a button; send a custom event that is bubbling. You may need to include some identifier for the form application that this button represents.

Listening for an event in a list class using the addEventListener () method. You cannot use MXML since you will use the undefined custom event in the default metadata of the list.

In your listener, make the appropriate user interface changes to display your form application.

+2
source

Source: https://habr.com/ru/post/1396609/


All Articles