Link to home
Start Free TrialLog in
Avatar of SreeramojuPradeep
SreeramojuPradeepFlag for India

asked on

Menu control in flex with xml data

Hi,

I have two problems in flex menu control......

---1.  Is there any way in which we can handle null values in menu control...        
         
                     in the below code snippet some menuitems value in the xml is equal to null,
if it is null i would not like to display in dropdown i.e

private function createAndShow():void {
                       '      '
                       '       '
          menu.show(10, 10);
}

   
<menuitem label="MenuItem A">
                <menuitem label="SubMenuItem A-1"
                          url="link1"/>
                <menuitem label="SubMenuItem A-2"
                          url="link2"/>
            </menuitem>
            <menuitem label="MenuItem B">
                <menuitem label="SubMenuItem B-1"
                          url="link3"/>
                <menuitem label="null"
                          url="link4"/>
                <menuitem label="null"
                          url="link5"/>
	    </menuitem>

Open in new window


--->2.  In menu item click event

using       event.item.@label....gives label of  the menu clicked

Is there any way in which we can get the main menu label, submenu1 label and submenu2 label using menu item click event

mainmenu ----->submenu1-------------------------------->submenu2
         |                             |                                                               |
         |                             |                                                               |
       label               label of submenu1                          label of submenu2
       of main menu

In menu control of flex...................................

Thanks & Regards




Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

1. If you happen to have null for a label, you need to delete the node from xml data structure.
2. Menu click Event can give you all details.


Here is complete working code.

ASKER CERTIFIED SOLUTION
Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SreeramojuPradeep

ASKER

I got the solution for my first problem...Thanks for that

But in menu item click event is there any way in which we can get main menu label + submenu1 label +
event.item.@label gives only SubMenuItem A-2

But i want main menu label with submenu label also  
event.item.@label gives only  ------> submenu label


<menuitem label="MenuItem A" >
       <menuitem label="SubMenuItem A-1" visible="false" includeInLayout="false"/>
        <menuitem label="SubMenuItem A-2"/>        
</menuitem>

I am using the below query to generate xml form sqlite table its working fine..........
i am thinking to include one more field with label1 but i am getting syntax error.....
label1 value will be equal to mainmenulabel+submenu1label...
which might solve the problem......................using these values i should do local search...from my app

 
SELECT '\n\t<menuitem label=\"' || ClientName || '\">\n' || GROUP_CONCAT('\t\t<menuitem label=\"' || CaseType || '\">\n\t\t\t<menuitem label=\"' || CaseNum || '\"/>\n\t\t</menuitem>', '\n') || '\n\t</menuitem>' AS menuitem FROM clientDetails GROUP BY ClientName;

Open in new window

And also the code u gave me checks only the label of menu menu but not submenu

if
<menuitem label="null" type="check" toggled="true"/>
            <menuitem label="MenuItem A" >
                <menuitem label="null" />
                <menuitem label="SubMenuItem A-2"/>
</menuitem>
let me know if u need more clarifications on the same..............
i got the solution for deleting the sub nodes....by using nested foreach loop

 
var cNXmlList:XMLList = new XMLList(xmlListCN);
				for each (var node:XML in cNXmlList.children()) {
					for each (var subnode:XML in node.children()){
						for each (var subnodechild:XML in subnode.children()){
							if (subnodechild.@label != 'null') {
								trace(subnodechild.@label);
								trace(subnodechild.children().length());
							}
							else {
								delete subnodechild.(@label=='null')[0];
							}
						}
					}
				}

Open in new window


let me know if any mistakes....

Can u pls give me the solution for second problem.....

Hi,

I got solution for both......

Thanks for ur support .....

If possible can u let me know how to give tool tips for...

main menu---> submenu ------> while creating xml itself
MenuItem default itemrenderer does not support tooltip.

But by implementing custom intemrenderer, you can do this.

Look at the emaple code. I am sure you can adopt to suit your needs.

http://www.jusfortechies.com/flex/display-tooltip-in-menu.php