在应该没有错误的地方获取错误

时间:2019-05-31 21:13:12

标签: javascript arrays jquery-selectors element

我不知道为什么要求我将逗号放在句点应放置的位置。 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文件中使用。 ';'预期。 ','预期。 ','预期。 意外的标记。预期使用构造函数,方法,访问器或属性。 需要声明或声明。

0 个答案:

没有答案