You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node Red函数节点中if判断失效问题求助

问题原因及解决方法

你的代码判断不生效的核心问题是类型不匹配:

  • msg.status.text获取到的是字符串类型的"true",而非布尔值true
  • 你使用的全等运算符===会同时检查值和类型,字符串"true"与布尔值true类型不同,导致条件永远无法满足

修正代码

将判断条件改为匹配字符串即可,同时别忘了把结果赋值给msg.payload并返回,否则下游文本节点无法接收数据:

var totale = "inizio";
var messaggio = msg.status.text;
if (messaggio === "true") {
    totale = "abc";
}
msg.payload = totale;
return msg;

内容的提问来源于stack exchange,提问作者stradivar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 07:34:53