英文:
How can I destroy the mmenu plugin
问题
我有一个使用Mmenu插件制作的菜单。我在小于1025px的分辨率下初始化它。我在resize内部进行初始化。我需要在大于1025的权限下销毁mmenu,以便显示通常的桌面菜单。现在我的问题是,控制台中出现错误 - 无法读取未定义的属性(读取“destroy”)。我该如何解决这个问题?
$(window).resize(function(e) {
if ($(window).width() < 1025) {
$menu.mmenu({
"offCanvas": {
"position": "left"
},
"navbar": {
"title": ""
},
"theme": "light"
});
const api = $menu.data("mmenu");
} else if ($(window).width() > 1025) {
const api = $menu.data("mmenu");
api.destroy();
}
});
注意:这是代码部分的翻译,不包括代码本身。
英文:
I have a menu which is made using the Mmenu plugin. I initialize it at resolutions less than 1025px. I initialize inside resize. I need to destroy mmenu on permissions greater than 1025 so that the usual desktop menu is displayed. Now my problem is that I have an error in the console - Cannot read properties of undefined (reading 'destroy'). How can I solve this problem?
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
$(window).resize(function(e) {
if ($(window).width() < 1025) {
$menu.mmenu({
"offCanvas": {
"position": "left"
},
"navbar": {
"title": ""
},
"theme": "light"
});
const api = $menu.data("mmenu");
} else if ($(window).width() > 1025) {
const api = $menu.data("mmenu");
api.destroy();
}
});
<!-- end snippet -->
答案1
得分: 1
这可能是因为,当您尝试访问属性(destroy())时,其中包含未定义,并且尚未分配一个值。有可能destroy()是一个箭头函数,而值或函数将在稍后分配。
英文:
This could be because, when you try to access a property (destroy()), it has undefined in it and hasn't been assigned a value. It is possible that destroy() is an arrow function and that a value or function is to be assigned later.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论