Node Red 中的 Javascript Else If 语句有问题
Having problems with Javascript Else If statement in Node Red
我整天都在和这个问题作斗争。这是我的代码片段,else if
中的第 5 行是事情变得棘手的地方。我也是 Javascript 的新手,所以这可能是我无法发现错误的原因,但从我在其他地方看到的情况来看,这段代码应该可以工作。第 5 行和第 6 行的注释也被交换了。
if (msg.payload.License_Plate !== null) {
// This portion checks for a valid number plate
if (readlpr == dblpr); { // we have a direct match, open the gate
opengate = 1; // will send open signal to gpio
} else if(readlpr !== null); { // from here on, we are checking for a partial plate match
validdigits = 0; // make sure we have data before continuing, as may be a rfid match
{
if (!context.count); { // check to see if counter already used, if not initialise it
context.count = 0;
错误消息图片
您有一些错误:
if (readlpr == dblpr); {
...
} else if(readlpr !== null); {
...
if (!context.count); {
还有一个额外的左大括号。
这些结尾不应该有分号:
if (readlpr == dblpr) {
...
} else if(readlpr !== null) {
...
if (!context.count) {
最后应该是这样的:
if (msg.payload.License_Plate !== null) {
if (readlpr == dblpr) {
opengate = 1;
} else if(readlpr !== null) {
validdigits = 0;
// { <!-- Remove this as well, it's an extra brace
if (!context.count) {
context.count = 0;
我整天都在和这个问题作斗争。这是我的代码片段,else if
中的第 5 行是事情变得棘手的地方。我也是 Javascript 的新手,所以这可能是我无法发现错误的原因,但从我在其他地方看到的情况来看,这段代码应该可以工作。第 5 行和第 6 行的注释也被交换了。
if (msg.payload.License_Plate !== null) {
// This portion checks for a valid number plate
if (readlpr == dblpr); { // we have a direct match, open the gate
opengate = 1; // will send open signal to gpio
} else if(readlpr !== null); { // from here on, we are checking for a partial plate match
validdigits = 0; // make sure we have data before continuing, as may be a rfid match
{
if (!context.count); { // check to see if counter already used, if not initialise it
context.count = 0;
错误消息图片
您有一些错误:
if (readlpr == dblpr); {
...
} else if(readlpr !== null); {
...
if (!context.count); {
还有一个额外的左大括号。
这些结尾不应该有分号:
if (readlpr == dblpr) {
...
} else if(readlpr !== null) {
...
if (!context.count) {
最后应该是这样的:
if (msg.payload.License_Plate !== null) {
if (readlpr == dblpr) {
opengate = 1;
} else if(readlpr !== null) {
validdigits = 0;
// { <!-- Remove this as well, it's an extra brace
if (!context.count) {
context.count = 0;