0

How can i access every element value of my data.getReturnValue() because my c.getName is expectedly return a list of values.

({

myAction : function(component, event, helper) {
    var getAllRelatedContact = component.get("c.getName");
    getAllRelatedContact.setParams({
        "textsearch" : component.find("textsearch").get("v.value")
    });
    getAllRelatedContact.setCallback(this, function(data){
        var vals = data.getReturnValue();
        for(integer i=0;i<vals.length;i++){
            alert(vals[i]);
        }
    })
    $A.enqueueAction(getAllRelatedContact);  
}

})

2 Answers 2

0

Danryl,

If you want to access any value in the client side controller, then you can give like,

for(i=0;i<vals.length;i++)
{

  alert(vals[i].Name);//by accessing field name like in list.


  }

Else, If you want to just display accordingly, You can use in <aura:iteration> as Ashwani told.

<aura:iteration var="opp" *items="{!v.nameXYZ}"*>
        <p><b>  {!opp.Name} -- {!opp.Status}</b></p>
    </aura:iteration>

In controller,

component.set("v.nameXYZ", data.getReturnValue());
0
0

Simply write:

component.set("v.nameXYZ", data.getReturnValue());

Would be like:

({

myAction : function(component, event, helper) {
    var getAllRelatedContact = component.get("c.getName");
    getAllRelatedContact.setParams({
        "textsearch" : component.find("textsearch").get("v.value")
    });
    getAllRelatedContact.setCallback(this, function(data){
        var vals = data.getReturnValue();
        for(integer i=0;i<vals.length;i++){
            alert(vals[i]);
        }
        component.set("v.nameXYZ", data.getReturnValue());
    })
    $A.enqueueAction(getAllRelatedContact);  
}
})

v.nameXYZ is the attribute which expect list type value.

And if you want to show all items on page you can use <aura:iteration> tag

0

You must log in to answer this question.

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