Wednesday, September 5, 2018

Collection types in Salesforce Lightning

Basically,We have the below collection type available in lightning component.

1)Array
2)List
3)Map
4)Set


Let's discuss in detail:

1)Array:

To define the attribute for storing array values we can write:

<aura:attribute type="String[]" name="arrayattribute" default="['Apple','Orange','Mango']" />

Note:>Here we are storing some default values in "arrayattribute".
        >Array is a collection of defined data type.
        >Setting a default value without square brackets is deprecated and can lead to unexpected            behavior.


2)List:


To define the attribute for storing values in order we can write:

<aura:attribute type="List" name="Listattribute" default="['Apple','Orange','Mango']" />

Note:>Here we are storing some default values in "Listattribute".
         >List can have duplicates as well.
         >Setting a default value without square brackets is deprecated and can lead to unexpected behavior.


3)Map:


To define the attribute for mapping keys to values.

<aura:attribute type="Map" name="Mapattribute" default="{1:'value1',2:'value2'}" />

Note:>Here we are storing some default values in "Mapattribute".
         >Map cannot have duplicate keys.

A collection maps keys to values.  Each key can map to at most one value. Defaults to an empty object, {}. Retrieve values by using cmp.get("v.Mapattribute")['1'].


4)Set:


To define the attribute for Values which are unique.

<aura:attribute type="Set" name="Setattribute" default="['Apple','Orange','Mango']" />

Note:>Here we are storing some default values in "Setattribute".
         >Setcannot have duplicate Values.
         >Order for set item is not as it is when values are returned,It May be in same order or may change.
         >Setting a default value without square brackets is deprecated and can lead to unexpected behavior.
**************************************************************************************************************

No comments:

Post a Comment