Reply To: problem creating/appending menu dynamically

Home Forums Older releases 0.9.x problem creating/appending menu dynamically Reply To: problem creating/appending menu dynamically

#2312
admin
Keymaster

Yep, just call the refresh API method:

http://www.smartmenus.org/docs/#refreshInstance

after you append the sub menu and it should work – e.g. try this:

$('#Action').click(function() {

	// append sub menu
	$("#wsnmotes > ul").append(
	  '<li id="wsnnode"><a href="#"><i class="fa fa-plus-square"></i> mote name: L1</a>'+
	    '<ul id="sub1" class="dropdown-menu">'+
	      '<li><a href="#"><i class="fa fa-question-circle"></i> Discover</a> </li>'+
	      '<li><a href="#"><i class="fa fa-info-circle"></i> Mote Config</a></li>'+
	    '</ul>'+
	    '</li>'
	);

	// refresh menu tree after the DOM change
	$("#my-nav").smartmenus('refresh');
});

Also just make sure you set the “my-nav” id to your nav so that you can reference it in your script:

<ul id="my-nav" class="nav navbar-nav">...

Register

You will be emailed a link to set your password.

Login

Lost password?