Generally In every component implementation we have a need to change
the UI conditionally, or show/hide a section/column based on certain
conditions. We need simple ways to do this instead of having every
handler in code. Below are key operators and their syntax to handle any
such situation
Math Functions
The math functions perform math operations on numbers. They
take numerical arguments. The Corresponding Operator column lists
equivalent operators, if any.
add |
concat |
add(1,2) |
Adds the first argument to the second. |
+ |
sub |
subtract |
sub(10,2) |
Subtracts the second argument from the first. |
– |
mult |
multiply |
mult(2,10) |
Multiplies the first argument by the second. |
* |
div |
divide |
div(4,2) |
Divides the first argument by the second. |
/ |
mod |
modulus |
mod(5,2) |
Returns the integer remainder resulting from dividing the first argument by the second. |
% |
abs |
|
abs(-5) |
Returns
the absolute value of the argument: the same number if the argument is
positive, and the number without its negative sign if the number is
negative. For example, abs(-5) is 5. |
None |
neg |
negate |
neg(100) |
Reverses the sign of the argument. For example, neg(100) is -100. |
– (unary) |
String Functions
concat |
add |
concat(‘Hello ‘, ‘world’)
add(‘Walk ‘, ‘the dog’)
|
Concatenates the two arguments. |
+ |
format |
|
format($Label.ns.labelName, v.myVal)
|
Replaces any parameter placeholders with comma-separated attribute values. |
|
join |
|
join(separator, subStr1, subStr2, subStrN)
join(‘ ‘,’class1’, ‘class2’, v.class)
|
Joins the substrings adding the separator String (first argument) between each subsequent argument. |
|
Label Functions
format |
format($Label.np.labelName, v.attribute1 , v.attribute2)
format($Label.np.hello, v.name)
|
Outputs
a label and updates it. Replaces any parameter placeholders with
comma-separated attribute values. Supports ternary operators in labels
and attributes. |
Informational Functions
length |
myArray.length |
Returns the length of an array or a string. |
empty |
empty(v.attributeName)
|
Returns true if the argument is empty. An empty argument is undefined, null, an empty array, or an empty string. An object with no properties is not considered empty.
The $A.util.isEmpty() method in JavaScript is equivalent to the empty() expression in markup.
|
Comparison Functions
Comparison functions take two number arguments and return true or false depending on the comparison result. The eqand ne functions can also take other data types for their arguments, such as strings.
equals |
equals(1,1) |
Returns true if the specified arguments are equal. The arguments can be any data type. |
== or eq |
notequals |
notequals(1,2) |
Returns true if the specified arguments are not equal. The arguments can be any data type. |
!= or ne |
lessthan |
lessthan(1,5) |
Returns true if the first argument is numerically less than the second argument. |
< or lt |
greaterthan |
greaterthan(5,1) |
Returns true if the first argument is numerically greater than the second argument. |
> or gt |
lessthanorequal |
lessthanorequal(1,2) |
Returns true if the first argument is numerically less than or equal to the second argument. |
<= or le |
greaterthanorequal |
greaterthanorequal(2,1) |
Returns true if the first argument is numerically greather than or equal to the second argument. |
>= or ge |
Boolean Functions
Boolean functions operate on Boolean arguments. They are equivalent to logical operators.
and |
and(isEnabled, hasPermission) |
Returns true if both arguments are true. |
&& |
or |
or(hasPermission, hasVIPPass) |
Returns true if either one of the arguments is true. |
|| |
not |
not(isNew) |
Returns true if the argument is false. |
! |
Conditional Function
if |
if(isEnabled, ‘Enabled’, ‘Not enabled’) | | | | | | | | | | | |
Source :
http://www.saasanalogy.com/conditional-functions-in-salesforce-lightning/
Comments
Post a Comment