简体   繁体   English

javascript 数组逻辑无法正确呈现以与地图组件反应

[英]javascript array logic not rendering properly in react with map component

This is a pretty interesting issue I'm facing.这是我面临的一个非常有趣的问题。 So basically I have two files:所以基本上我有两个文件:

When dtmf is 1, found should return true and the rest of the code should run smoothly.当 dtmf 为 1 时,found 应返回 true,其余代码应顺利运行。 But for some reason, found returns false which ruins the rest of the code.但是由于某种原因, found 返回 false ,这会破坏其余的代码。 I tested the logic in a separate js compiler with the values in the screenshot below and the logic worked fine.我使用下面屏幕截图中的值在单独的 js 编译器中测试了逻辑,逻辑运行良好。

Not sure why React is behaving this way.不知道为什么 React 会这样。 It seems as if the variables are not being rendered properly.似乎变量没有正确呈现。 Maybe need to wait for them to be fully initialized or something?也许需要等待它们完全初始化或什么的?

Let me know.让我知道。 Been working at this for a while and got nowhere.在这方面工作了一段时间,但一无所获。 Any help would be very appreciated.任何帮助将不胜感激。 Console output控制台输出

The problem is that you're comparing two different types:问题是您正在比较两种不同的类型:

  • Your dmtfs is an array of { value: string; label string }您的dmtfs是一个{ value: string; label string }数组{ value: string; label string } objects. { value: string; label string }对象。 Even though the strings represent numbers, they're still strings.即使字符串代表数字,它们仍然是字符串。
  • Your ìvr_dests uses actual numbers for the dtmf` field.您的 ìvr_dests uses actual numbers for the dtmf 字段的uses actual numbers for the

Therefore, you're comparing '1' === 1 which returns false due to being different types.因此,您正在比较'1' === 1由于类型不同而返回 false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM