Topic: Mif.menu and list items
Hi all,
Knows anybody if it's possible to fill the menu list items dynamically.
I found an example to do so for the sub items but none for the main items.
Thanks for the help
You are not logged in. Please login or register.
Pages 1
Hi all,
Knows anybody if it's possible to fill the menu list items dynamically.
I found an example to do so for the sub items but none for the main items.
Thanks for the help
menu will be rewriten and transform functionalyti will be added. Now you can fill main menu using this code:
var list=myMenu.list;
list.options.items=[
{
name: 'item1'
},
{
name: 'item2',
}
];
list.items=[];
list.list.innerHTML='';
list.initMenu();
list.drawMenu();Thanks moro,
your code work fine, but when I am triing to load the menu items via xhtml request (Mootools Request.JSON)
my onAction functions do not get handled.
Do you have a clue what could be the reason
window.addEvent('domready',function(){
//init a empty menu
mmenu=new Mif.Menu({
contextmenu: true,
target: $('tree_container'),
offsets: {x:0, y:0},
initialize: function(){
new Mif.Menu.KeyNav(this);
},
list: {items:[]}
});
//build the tree
tree = new Mif.Tree({
....
});
// load tree from url.
tree.load({
....
});
//add the context menu functionality
tree.container.addEvent('contextmenu', function(event){
var node=tree.mouse.node;
if(!node) return;
//modifiing the menu items
//this lines works fine (action functions are handled)
var list=mmenu.list;
/*list.options.items=[
{
name: 'item1',
onAction: function(){
alert('test');
}
},
{
name: 'item2',
}
];
//but when i try to load the menu items via xhtml Request (Mootools Request.JSON)
//my action functions are not handled
menuItems = SimpleDb.loadContextMenu(node.type);
list.options.items = menuItems;
list.items=[];
list.list.innerHTML='';
list.initMenu();
list.drawMenu();
mmenu.show(event);
return false;
});
tree.addEvent('mousedown', function(){
if (!mmenu) return;
mmenu.hide();
});
});Php code to get the menu items
$items = array();
$items[0]["name"] = "Item A";
$items[0]["onAction"] = "function(){alert('do something')}";
$items[1]["name"] = "Item B";
$items[2]["name"] = "Item C";
$items[3]["name"] = "Item D";
echo(json_encode($items));thanks again,
Jeff
Hmm the problem seems to be the php code
If I write my json string without using the php json_encode($str) function it works perfectly.
$jsonResult = '[{
"name": "Item 1",
"icon": "mif-menu-add-icon",
"onAction": function(){alert(\'do something\');}
},
{
"name": "Item 2",
"icon": "mif-menu-edit-icon",
"onAction": function(){ alert(\'do something\');}
}]';
echo($jsonResult);good, it's because json_encode return string
"function(){alert('do something')}"
but you want
function(){alert('do something')}Posts [ 5 ]
Pages 1
Powered by PunBB