Here is the basic example for iterating a collection or list of values in lightning component using aura:iteration tag.
Step 1:
Open Developer Console
Step 2:
Click File --> New --> Lightning Component --> Enter name as "DisplayNumbers" and Submit.
Clear the existing code and paste the below one,
Step 1:
Open Developer Console
Step 2:
Click File --> New --> Lightning Component --> Enter name as "DisplayNumbers" and Submit.
Clear the existing code and paste the below one,
- <aura:component >
- <aura:attribute name="numbers" type="List"/>
- <ui:button press="{!c.getNumbers}" label="Display Numbers" />
- <aura:iteration items="{!v.numbers}" var="num">
- <br/> Number: {!num.value}
- </aura:iteration>
- </aura:component>
Step 3:
Double Click on Controller in right hand side of the component. Clear the existing code and paste the below one,
- ({
- getNumbers: function(component) {
- var numbers = [];
- for (var i = 0; i < 10; i++) {
- numbers.push({
- value: i
- });
- }
- component.set("v.numbers", numbers);
- }
- })
Create a lighting app and refer the above created lightning component and run it.
Output:
No comments:
Post a Comment