有人可以尝试向我解释为什么“If”语句允许它通过但很明显你可以看到我的对象的属性说“现有”即使它说如果它只允许"new"。
var newChannalChecker = false;
singleMassiveGroup.forEach(singleGrop => {
if (!newChannalChecker && singleGrop.length) {
singleGrop.forEach(element => {
if (element["currentItemStatus"] === "NEW") {
newChannalChecker = true;
}
});
}
});
我不确定这是否有帮助,但我尝试将一些日志与它一起检查发生了什么
var newChannalChecker = false;
singleMassiveGroup.forEach(singleGroup => {
if (!newChannalChecker && singleGroup.length) {
// singleGrop.filter(e => e.CurrentItemStatus === "NEW").map(e)
singleGroup.forEach(element1 => {
console.log("CurrentItemStatus: ", element1.CurrentItemStatus);
if (element1.CurrentItemStatus === "NEW") {
console.log(
"Entered CurrentItemStatus: ",
element1.CurrentItemStatus
);
newChannalChecker = true;
}
});
}
});
App.js:402 CurrentItemStatus: EXISTING
奇怪的是它说值是“EXISTING”,但它仍然在 if 中
我尝试将鼠标悬停到它显示“Element1 未定义”的属性
还有一件事我注意到“If”语句中的 console.log 没有打印任何内容,但它仍然将 newChannalChecker 更改为 True
最佳答案
我在 chrome devtools 上看到了一些类似的问题,
做一件事
console.log(element["currentItemStatus"]
在 if block 内,
它应该给你正确的值。那将不仅仅是NEW
关于javascript - 为什么它经历了 if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52524064/