jquery - Magento 2:展开/折叠侧边栏菜单
问题描述
我正在尝试运行以下脚本以在 magento 2 中添加展开/折叠,但是当在前端单击事件时会生成错误。
Uncaught ReferenceError: $header is not defined
我正在使用的代码是
define([
"jquery"
], function($){
"use strict";
return function sidebar(config, element) {
$(".filter-ab").click(function () {
$header = $(this);
//getting the next element
$content = $header.next();
//open up the content needed - toggle the slide- if visible, slide up, if not slidedown.
$content.slideToggle(500, function () {
//execute this after slideToggle is done
//change text of header based on visibility of content div
$header.text(function () {
//change text based on condition
return $content.is(":visible") ? "Collapse" : "Expand";
});
});
});
}
});
解决方案
我认为您需要使用 var header 而不是 $header
推荐阅读
- react-native - 在 InitialScrollIndex 之后平面列表滚动不起作用
- elasticsearch - ElasticSearch 数字距离
- powershell - Net Use 和 ForEach 与 PowerShell 中的变量
- ionic-framework - 如何加载html代码
- angular - Angular 6:直接在表格中搜索而不按回车
- identityserver4 - 如何使用 IdentityServer4 创建 JWT 令牌
- python - '一个系列的真值是模棱两可的。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。
- r - Dplyr 变异循环
- android - FCM,未接收数据
- c# - 使用自定义属性将数据表映射到列表的通用函数