javascript - 在不应该出现的地方出现错误
问题描述
我不知道为什么我被要求在句号应该放置逗号的地方放置逗号。const 卡是说当这是设置变量的方法时我不能在那里设置它。
我试图从 const 更改为 let 并重组 .forEach 语法
class TabLink {
constructor(tabElement) {
// assign this.tabElement to the tabElement DOM reference
this.tabElement = tabElement;
// Get the `data-tab` value from this.tabElement and store it here
this.tabData = this.tabElement.dataset.tab;
// We need to find out if a user clicked 'all' cards or a specific category. Follow the instructions below to accomplish this task:
// Check to see if this.tabData is equal to 'all'
if (this.tabElement.dataset.tab === "all") {
// If `all` is true, select all cards regardless of their data attribute values
this.cards = document.querySelectorAll(".card");
} else {
// else if `all` is false, only select the cards with matching this.tabData values
this.cards = document.querySelectorAll(`.card[tabData="${this.tabData}"]`);
}
// Map over the newly converted NodeList we just created in our if statement above. Convert each this.cards element into a new instance of the TabCard class. Pass in a card object to the TabCard class.
this.cards = Array.from(this.cards).map((card) => new TabCard(card));
// Add a click event that invokes this.selectTab
this.tabElement.addEventListener('click', () => { this.selectTab() });
}
selectTab() {
// Select all elements with the .tab class on them
// const tabs = document.querySelectorAll();
const tabs = document.querySelectorAll('.tab');
// Iterate through the NodeList removing the .active-tab class from each element
Array.from(tabs).forEach((tabs))
link.classList.remove(".active-tab");
}
//
// Select all of the elements with the .card class on them
const cards = document.querySelectorAll('.card');
// Iterate through the NodeList setting the display style each one to 'none'
cards.forEach(card => {
card.style.display = "none";
})
// Add a class of ".active-tab" to this.tabElement
this.tabElement = ".active-tab";
// Notice we are looping through the this.cards array and invoking selectCard() from the TabCard class. Just un-comment the code and study what is happening here.
this.cards.forEach(card => card.selectCard());
console.log(this.cards);
}
'const' 只能在 .ts 文件中使用。';' 预期的。',' 预期的。',' 预期的。意外的标记。需要构造函数、方法、访问器或属性。预期声明或声明。
解决方案
推荐阅读
- pandas - Pandas - 将行拆分为多列时出错
- c# - 如何在 Visual Studio C# 中制作一个将特定文本插入文本框中的按钮?
- javascript - 如何在 Microsoft Teams sdk 上使用后退按钮处理程序
- java - 是否有必要在 Hibernate 的 Proxy 对象的哈希码实现中使用 getter?
- datetime - 带有谷歌驱动表的 Arduino 数据记录器
- javascript - div上的ScrollTop,Vuejs
- r - 提取文本中的第一个括号,其中包含一些观察的条件
- python - 在 Mac OSX Catalina 上运行 Python 3+ 时遇到问题
- powershell - 如何将大量 Powershell 脚本合并为一个
- spring - 我不能交朋友 Thymeleaf 和 Spring