Start a new discussion

To start a new discussion please visit the discussions section of the GitHub home page of the project.

Discussions on GitHub

You can also search our old self-hosted forums for any useful information below but please note that posting new content here is not possible any more.

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">...