0

I am not sure why aura:iteration is displaying blank list of values.I can see that p.id is repeating 5 times but it is showing blank values.Please help Below is my component-ContactItemList.cmp

<aura:component controller="ContactItemListController" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="contacts" type="Contact[]"/>
<aura:iteration items="{!v.contacts}" var="p">
    -->{!p.id}
</aura:iteration>

Below is my client side controller-ContactItemListController.js

({
doInit : function(component, event, helper) {
    helper.getContacts(component);
}
})

Below is my server sider controller-ContactItemListController.apxc

public class ContactItemListController {
@AuraEnabled
public static List<Contact> getContacts() {
    List<Contact> cList=[select id from Contact limit 5];
    System.debug('-------->'+cList.size());
    return cList;//[select id, name from contact limit 100];//cList;
}}

Below is my helper file-ContactItemListHelper.js

({
getContacts: function(component) {
    var action = component.get("c.getContacts");
    action.setCallback(this, function(a) {
        component.set("v.contacts", a.getReturnValue());
        console.log("**"+a.getReturnValue());
    });
    $A.enqueueAction(action);
}})

2 Answers 2

2

Please replace the code {!p.id} with {!p.Id} in component-ContactItemList.cmp. Let me know if it works.

1
  • It would be nice to provide explanation like post below. This will also help the future readers.
    – Wayne Ni
    Commented Dec 1, 2022 at 0:11
2

Expanding on @Nebula's correct suggestion the reason that values are not being emitted is that expressions in Lightning are (like JavaScript and most other programming languages) case sensitive. The property names "id" and "Id" are not equivalent so p.id is looking in the wrong place. With that said an error message to that effect would be very helpful to avoid this common mistake (there is a story for that but I do not have an ETA).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .