PDA

View Full Version : creating menu and submenu dynamically



criticalmind
5 Mar 2008, 10:13 PM
hi,

im creating a popup menu, dynamically..im getiting data for the menu, via json. here's how i did it:

var cx=new Array();
var cm=new Ext.menu.Menu();
for(var i = 0; i<cjson.length; i++){
if(cjson[i].id ==123){
cm.add(
cx[i]=new Ext.menu.Item({text: cjson[i].title+' >>',
icon: cjson[i].iconPath
,menu:{
items:[
{text:'a'},{text:'b'}
]
}
})
);
}else{
cm.add(
cx[i]=new Ext.menu.Item({text: cjson[i].title,
icon: cjson[i].iconPath})
);
}
}

//so far this code, is functioning well on my machine. my issue is, how to create the //submenu dynamically also.

pls help. tnx

aurelien
8 Mar 2008, 2:12 PM
Hi -

I was working on the exact same problem...

You have to create an Array containing your Ext.Menu.Item representing your submenu and put the array as a config menu of the parent menu.


var sub = new Array();
sub[0] = new Ext.menu.Item({
text: 'sub-menu 0 here'
});
sub[1] = new Ext.menu.Item({
text: 'sub-menu 1 here'
});

cx[i]=new Ext.menu.Item({
text: cjson[i].title+' >>',
icon: cjson[i].iconPath,
menu: new Ext.menu.Menu({
items: sub
}
})

I hope this helps...
Aurelien