Newer Version Available

This content describes an older version of this product. View Latest

Collection Types

Here are the supported collection type values.

type Example Description
List <aura:attribute name="colorPalette" type="List" default="red,green,blue" /> An ordered collection of items.
Map <aura:attribute name="sectionLabels" type="Map" default="{ a: 'label1', b: 'label2' }" /> A collection that maps keys to values. A map can’t contain duplicate keys. Each key can map to at most one value. Defaults to an empty object, {}. Retrieve values by using cmp.get("v.sectionLabels")['a'].
Set <aura:attribute name="collection" type="Set" default="1,2,3" /> A collection that contains no duplicate elements. The order for set items is not guaranteed. For example, "1,2,3" might be returned as "3,2,1".

Setting List Items

There are several ways to set items in a list. To use a client-side controller, create an attribute of type List and set the items using component.set().

This example retrieves a list of numbers from a client-side controller when a button is clicked.

1swfobject.registerObject("clippy.codeblock-0", "9");<aura:attribute name="numbers" type="List"/>
2<ui:button press="{!c.getNumbers}" label="Display Numbers" />
3<aura:iteration var="num" items="{!v.numbers}">
4  {!num.value}
5</aura:iteration>
6
1swfobject.registerObject("clippy.codeblock-1", "9");/** Client-side Controller **/
2({
3  getNumbers: function(component, event, helper) {
4    var numbers = [];
5    for (var i = 0; i < 20; i++) {
6      numbers.push({
7        value: i
8      });
9    }
10    component.set("v.numbers", numbers); 
11    }
12})
13

To retrieve list data from a controller, you can use aura:iteration. See aura:iteration for more information.

Setting Map Items

To add a key and value pair to a map, use the syntax myMap['myNewKey'] = myNewValue.
1swfobject.registerObject("clippy.codeblock-2", "9"); var myMap = cmp.get("v.sectionLabels");
2 myMap['c'] = 'label3';
The following example retrieves data from a map.
1swfobject.registerObject("clippy.codeblock-3", "9");for (key in myMap){
2     //do something
3}
4