javascript - React ANTD DatePicker HTMLCollection 在提取元素/值时不显示实时值
问题描述
当我使用 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
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 已更新并 siaplays '后来的'值,并且在我的代码中,我在尝试从中提取特定值之前和之后读取较新的值,这些值如何不存在?
任何帮助真的很感激!
解决方案
所以这似乎是真实与虚拟 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 - 在排序函数的 js 中重构一个简单的返回语句
- python - Matlib 或 Plotly 条形图 Race Graph
- c++ - 在模板类中初始化一个固定长度的数组
- ios - iOS 模拟器设置中缺少“重置键盘字典”选项
- javascript - 为什么我的 Scriptlet 不工作 html Apps 脚本
- jquery - 将 jQuery replaceWith 重构为箭头函数的正确方法是什么?
- azure - Azure blob 的 AzureSigningError
- android - Android Q 上已弃用的 WifiManager.getConfiguredNetworks 和 WifiManager.removeNetwork 方法的替代方案?
- javascript - 如何使用反应测试库测试这个组件 - 只是这个新测试库的初学者
- python - Pandas 数据框搜索的一站式解决方案