我使用節點紅和我有以下傳入msg.payload:通過循環數組和解析
[ "=00ECY20WA200_RECV_P1SEL", "true", "=00ECY20WA200_RECV_P2SEL", "true", "=00ECY20WA300_RECV_P2SEL", "true", "=00ECY20WA300_RECV_P1SEL", "true", "=00ECY20WA202_RECV_P1SEL", "true", "=00ECY20WA202_RECV_P2SEL", "false", "=00ECY20WA303_RECV_P2SEL", "true", "=00ECY20WA303_RECV_P1SEL", "true", "=00ECY20WA204_RECV_P1SEL", "false", "=00ECY20WA204_RECV_P2SEL", "true", "=00ECY20WA305_RECV_P2SEL", "false", "=00ECY20WA305_RECV_P1SEL", "false", "=00ECY20WA205_RECV_P1SEL", "false", "=00ECY20WA205_RECV_P2SEL", "false", "=00ECY20WA306_RECV_P1SEL", "true", "=00ECY20WA306_RECV_P2SEL", "true", "=00ECY20WA206_RECV_P1SEL", "false", "=00ECY20WA206_RECV_P2SEL", "true", "=00ECY20WA307_RECV_P1SEL", "true", "=00ECY20WA307_RECV_P2SEL", "true", "=00ECY20WA207_RECV_P1SEL", "false", "=00ECY20WA207_RECV_P2SEL", "false", "=00ECY20WA308_RECV_P1SEL", "false", "=00ECY20WA308_RECV_P2SEL", "true", "=00ECY20WA208_RECV_P1SEL", "false" ]
我試圖解析所有這些都是「真」的項目,將它們連接起來在數組(recievingAlarms)中,解析的項目位於布爾運算符之前。我試圖用for循環來做到這一點,我很確定我創建了一個無限循環,我不知道如何糾正它。這裏是我有:
代替'1 + 2'使用'I + = 2'。將條件'msg.payload [i] === true'改爲'msg.payload [i] == true',因爲'「true」'是一個字符串或者與字符串「true」比較而不是布爾值true '。還有'recievingAlarms = recievingAlarms.concat(msg.payload [i-1]);' – RaR
甚至'msg.payload [i] ==='true'' –