javascript - 为什么它经历了 if

标签 javascript reactjs

有人可以尝试向我解释为什么“If”语句允许它通过但很明显你可以看到我的对象的属性说“现有”即使它说如果它只允许"new"。

enter image description here

 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 中

enter image description here

enter image description here

我尝试将鼠标悬停到它显示“Element1 未定义”的属性

还有一件事我注意到“If”语句中的 console.log 没有打印任何内容,但它仍然将 newChannalChecker 更改为 True

最佳答案

我在 chrome devtools 上看到了一些类似的问题,

做一件事

console.log(element["currentItemStatus"] 在 if block 内,

它应该给你正确的值。那将不仅仅是NEW

关于javascript - 为什么它经历了 if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52524064/

相关文章:

reactjs - 使用 firebase-functions 部署基于 React 的 SSR 应用程序时出错

javascript - 通过搜索/比较自动增加值并匹配 Google Sheets 脚本中的两列

javascript - 为什么我的 ng-repeat 不起作用?

javascript - 从getter返回的函数的 `this`关键字的值

javascript - React.js : How to use the same button while passing variables to a click function

javascript - 如何使用 React 启用/禁用自定义验证按钮

javascript - 使用 process.nextTick 或 setImmediate 创建等待函数 - node.js

javascript - 为什么 eslint 考虑 JSX 或一些 react @types undefined,因为将 typescript-eslint/parser 升级到版本 4.0.0

javascript - 带有 ReactJS 的 Material Design Lite(导入/要求问题)

javascript - React - 在 map 函数中表达预期