No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Working with Attribute Values in JavaScript
These are useful and common patterns for working with attribute
values in JavaScript.
Example
In these examples, cmp is a reference to a
component in your JavaScript code. It’s usually easy to get a reference to a component in
JavaScript code.
Get an Attribute Value
To get the value of a component’s label attribute:
1var label = cmp.get("v.label");Set an Attribute Value
To set the value of a component’s label attribute:
1cmp.set("v.label","This is a label");Get a Boolean Attribute Value
To get the boolean value of a component’s myString attribute:
1var myString = $A.util.getBooleanValue(cmp.get("v.myString"));1<aura:attribute name="myString" type="String" default="my string"/>Validate that an Attribute Value is Defined
To determine if a component’s label attribute is defined:
1var isDefined = !$A.util.isUndefined(cmp.get("v.label"));Validate that an Attribute Value is Empty
To determine if a component’s label attribute is empty:
1var isEmpty = $A.util.isEmpty(cmp.get("v.label"));