1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

SwitchNode: allow use of properties beneath the top level

This commit is contained in:
Nicholas O'Leary 2013-10-19 21:04:17 +01:00
parent 547ae0cd72
commit f8e8bf22c0

View File

@ -39,14 +39,18 @@ function SwitchNode(n) {
this.rules = n.rules;
this.property = n.property;
var propertyParts = n.property.split(".");
var node = this;
this.on('input',function(msg) {
var onward = [];
var prop = propertyParts.reduce(function(obj,i) {
return obj[i]
},msg);
for (var i=0;i<node.rules.length;i+=1) {
var rule = node.rules[i];
if (operators[rule.t](msg[node.property],rule.v,rule.v2)) {
if (operators[rule.t](prop,rule.v,rule.v2)) {
onward.push(msg);
} else {
onward.push(null);