[SalesForce] Lightning Aura Iteration ReRender

I am trying to rerender an iteration(wrapper) when an input field is changed although I am extremely unfamiliar with Lightning. Everything that I've read it "it should just work", which I don't understand. The following the my component

<aura:component controller="AuraDisplayTeamMembers" implements="force:appHostable">    
    <aura:attribute name="accountPVAUserID" type="Account" default="{ 'sobjectType' : 'Account' }"/>
    <aura:attribute name="taskWrapper" type="AuraDisplayTeamMembers.TaskWrapper[]"/> 
    <aura:handler name="change" value="{!v.accountPVAUserID}" action="{!c.searchUser}"/>

    <force:inputField value="{!v.accountPVAUserID.PVA__c}"/>
    <aura:iteration var="taskWrapper" items="{!v.taskWrapper}" >
        <tr>
            <td><ui:outputText value="{!taskWrapper.subject}"/></td>
            <td><ui:outputText value="{!taskWrapper.ownerName}"/></td>
        </tr>
    </aura:iteration>
</aura:component>

The following component does return everything correct and what I read was by setting the cmp.set('v.taskWrapper', returnValue); it will tell the component to re-render which I don't fully understand right now. I can see in the console log my object coming back through. I looked around quite a bit and found examples but most of them are from 2015 and everything I've found I'm doing it correctly..

{
searchUser : function(cmp, event, page) {
    var action = cmp.get("c.searchForUser");

    var myAttribute = cmp.get("v.accountPVAUserID.PVA__c");
    action.setParams({ "objectID" : myAttribute });

    var str = JSON.stringify(myAttribute);
    str = JSON.stringify(myAttribute, null, 4); // (Optional) beautiful indented output.
    console.log(str); // Logs output to dev tools console.
    action.setCallback(this, function(response) 
    {
        var state = response.getState();
        console.log('The response.getReturnValue() ' + response.getReturnValue());

        if (state === "SUCCESS") 
        {
            console.log('Im successful');
            var returnValue = response.getReturnValue();
            cmp.set('v.taskWrapper', returnValue);
        }
    });

    $A.enqueueAction(action);
}
}

I'm going to post my controller code also, I believe I may be returning the wrong attribute, although I'm not clear on how to get the return value from searchFromUser

@AuraEnabled
public static List<TaskWrapper> searchForUser(String objectID) 
{

    List<TaskWrapper> result = new List<TaskWrapper>();
    System.debug('objectID ' + objectID);
    List<Task> openTasksByObjectID = [SELECT ID, Subject, OwnerID, Description, Owner.Name FROM Task WHERE OwnerID =: objectID];
    System.debug('openTasksByObjectID ' + openTasksByObjectID);
    for(Integer i = 0, j = openTasksByObjectID.size(); i < j; i++)
    {
        TaskWrapper tw = new TaskWrapper();
        tw.taskID =  openTasksByObjectID[i].ID;
        tw.subject = openTasksByObjectID[i].Subject;
        tw.ownerID = openTasksByObjectID[i].OwnerID;
        tw.description = openTasksByObjectID[i].Description;
        tw.ownerName = openTasksByObjectID[i].Owner.Name;

        result.add(tw);
    }

    System.debug('result ' + result);
    return result;
}


public class TaskWrapper
{
    public TaskWrapper(){}
    public ID taskID {get;set;}
    public String subject {get;set;}
    public String ownerID {get;set;}
    public String description {get;set;}
    public String ownerName {get;set;}
}

I'm not seeing any errors in the console, is there anything else I can do to debug?

enter image description here

Best Answer

Great question! You need to AuraEnable the properties in the wrapper class.

Related Topic