Comments (15)
I got it I had to change the code to:
var sideMenu = $(this.sideMenuContainer);
sideMenu.removeData("mm");
sideMenu.metisMenu();
from metismenu.
For angularJs I had to add a timeout to wait for the dom change before running metisMenu again
// After changes to dom
$timeout(function() {
var sideMenu = angular.element('[side-navigation]');
sideMenu.removeData("mm");
sideMenu.metisMenu();
});
from metismenu.
Yep, same problem here with my Angular app. Any way to circumvent this, otherwise I have to digg into the codebase :)
from metismenu.
Ok, just had a quick look on the codebase
$.fn[ pluginName ] = function (options) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
}
});
};
As can be seen the plugin remembers whether it has been already initialized. The line if (!$.data(this, "plugin_" + pluginName)) {
is the "culprit". Commenting the if
and consequently re-calling $(...).metisMenu()
seems to work.
Now there are different possibilities.
- simply removing the
if
clause - adding a refresh function...like
$(...).metisMenu('refresh')
or similar...
Any input from the author would be author @onokumus would be cool, I'm also willing to submit a pull request with the fix. π
from metismenu.
I have noticed that just re-calling $(element).metisMenu();
after adding the items will give the expected results. I have been using this without modifying any of the codebase. However, I'm not sure how this affects any registered events.
from metismenu.
That's kinda strange as according to the codebase this shouldn't be possible (if I'm not missing something). Are you sure you're using the latest version? Maybe in a previous one the plugin simply didn't have the if
clause.
from metismenu.
Agreed it is strange, a refresh
method would be nice. I'm using the latest v1.1.1
using the method I mentioned but a neater way to do it would be great.
from metismenu.
I got around this problem by using jQuery's removeData()
var sideMenu = $(this.sideMenuContainer);
sideMenu.removeData("plugin_metisMenu");
sideMenu.metisMenu();
from metismenu.
This problem is caused by it need init again when the dom is changed. Just add one line code to init will be ok.
$.fn[ pluginName ] = function (options) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
}
// add this case
else {
$.data(this, "plugin_" + pluginName).init();
}
});
};
And when you changed dom anywhere, the only thing you need to do is call the following code
$(selector).metisMenu();
from metismenu.
Thanks @thomasvanlankveld that worked for me. Haven't tried @arlen43 's solution.
from metismenu.
thanks @arlen43 ! your solution worked for me.
from metismenu.
Although it doesnt really work that well. I notice that the the navigation dropdown always stays open. And doesn't close. At least one stays open. When I refresh the page it works. We really need to find a way to reload the menu
from metismenu.
Ok so actually I figured out how to use @arlen43 solution but with the newest MetisMenu code
function Plugin(option) {
return this.each(function() {
var $this = $(this);
var data = $this.data('mm');
var options = $.extend({},
MetisMenu.DEFAULTS,
$this.data(),
typeof option === 'object' && option
);
if (!data) {
$this.data('mm', (data = new MetisMenu(this, options)));
} else {
$this.data('mm').init();
}
if (typeof option === 'string') {
data[option]();
}
});
}
Now things reload like normal
from metismenu.
this worked for me:
var sideMenu = $('#leftMenu');
sideMenu.removeData("mm");
sideMenu.metisMenu();
but, now, when i open a menu, im not able to close it unless i open another, so i always have an open menu.
from metismenu.
See #116
from metismenu.
Related Issues (20)
- 3.0.0-beta vs 3.0.3 HOT 2
- vue δΈε¦δ½δ½Ώη¨
- Problem with last version 3.0.4 HOT 13
- Clicking a link prevent navigate to the page HOT 5
- The opened < ul> element not collapse on click the <li> which do not have child <ul>.and also want to add active class to the <li> to those which do not have child<ul>
- Add SCSS styles
- Not Workin HOT 1
- Second click on item removes mm-active class HOT 3
- Scroll to link if the link is active and out of screen HOT 2
- Laravel 7.x SCSS compile error
- demo website 404 HOT 1
- .has-arrow::after arrow icon is not aligned correctly
- error - TypeError: this is undefined 'r'
- Yet another TypeError: $(...).metisMenu is not a function
- MetisMenu highlighting all the links if anchor tag links doesnt end with .html
- Is about multiple init air datepicker
- Flash menu on page reload fix HOT 1
- How to render a divider/separator ?
- DEBHUB
- Demo link domain expired
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metismenu.