问题
I have a json which will send me 3 fields.
attribute
operator
value
for example:
attribute:total
operator: >=
value:1000
In scala I want to compare that field_name value, against that condition_value, according to that operator
if($cart[$field_name][$operator][$condition_value])
//means if(cart['total']>=100)
return true
else
return false
Operators will be dynamic. Datatype of values will be dynamic, for example condition_value can be string or number. Can I achieve it in scala / play framework?
sample scala code of what I am trying to do (non working), rule is my input
val operator=rule.operator
val datatype="Int"
if((cart.\(rule.attribute.get)).as[datatype](operator)rule.value.as[datatype])
return true;
else
return false;
}
Thanks.
来源:https://stackoverflow.com/questions/27482488/scala-dynamic-datatype-and-operators