当我使用ANTD DatePicker并使用箭头转到下一个面板。 UI更新,但我无法从HTMLCollection或NodeList中提取实时值。

第一次打开面板:

    var yrCell = document.getElementsByClassName("ant-calendar-year-panel-year");

    console.log(yrCell) // logs 2019-2030 in a HTMLCollection

    for (let item of yrCell) {
        console.log(item.innerText); // logs 2019-2030
    }

    for (let i = 0; i < yrCell.length; i++) {
        console.log(yrCell[i]); // logs 2019-2030
    }

    console.log(yrCell) // logs 2019-2030 in a HTMLCollection

现在的问题是,当我单击面板上的“下一步”箭头时
javascript - 当提取元素/值时, react ANTD DatePicker HTMLCollection不显示实时值-LMLPHP
    var yrCell = document.getElementsByClassName("ant-calendar-year-panel-year");

    console.log(yrCell) // logs 2029-2040 in a HTMLCollection

    for (let item of yrCell) {
        console.log(item.innerText); // STILL logs 2019-2030
    }

    for (let i = 0; i < yrCell.length; i++) {
        console.log(yrCell[i]); // STILL logs 2019-2030
    }

    console.log(yrCell) // logs 2029-2040 in a HTMLCollection

如果HTMLCollection已更新且UI已更新并且siaplay播放“后”值,则在尝试从中提取特定值之前和之后,在我的代码中,我正在读取新值,这些值如何不存在?

任何帮助真的很感激!

最佳答案

因此,实际DOM和虚拟DOM似乎存在一些问题,当有人使用超时来解决其他问题时,我发现了结果。但是我在代码中尝试了一下,并解决了它,因此我将逻辑包装在其中。

setTimeout(() => {
    [...yearCells].forEach(yearCell => {
        for (var count = 0; count < this.state.yearsThatCoveragesWereChanged.length; count++) {
            if (this.state.yearsThatCoveragesWereChanged[count].effectiveFrom === yearCell.innerText) {
                 //logic
            }
        }
    });
}, 0);

关于javascript - 当提取元素/值时, react ANTD DatePicker HTMLCollection不显示实时值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60773484/

10-12 22:45