0

Hello I am having a hard time refreshing a component. I want to totally recreate a sub child component from a child component(parent of the sub child). I am trying to implement as given in Refresh child by recreating it from the parent . But not able to do so.

Parent Component

<aura:component access="global" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" controller="WspController">
   <!--All attributes-->

  <!--Child Component-->
  <c:questionSectionPolitic aura:id="childQuestion"  
                                      qstList="{!qstList}"
                                      recordId="{!v.recordId}"
                                      questionA="{!v.questionA}"
                                      questionB="{!v.questionB}"
                                      questionC="{!v.questionC}"
                                      questionD="{!v.questionD}"
                                      questionE="{!v.questionE}"
                                      questionF="{!v.questionF}"
                                      questionG="{!v.questionG}"
                                      questionH="{!v.questionH}"
                                      questionI="{!v.questionI}"
                                      questionJ="{!v.questionJ}"
                                      questionK="{!v.questionK}"
                                      questionL="{!v.questionL}"


              />
       <button type="button" aura:id="saveAndReturn" class="slds-button slds-button--neutral slds-button slds-button--brand slds-hide" onclick="{!c.saveAndReturn}" >Save and return
       </button>

</aura:component>

Parent Controller

 saveAndReturn: function (component,event,helper){
   // Some changes

    $A.createComponent(
               'c:questionSectionPolitic', {
                                      "aura:id":"childQuestion",
                                      "qstList": component.get("v.contactList"), 
                                      "recordId": component.get("v.recordId"),
                                      "questionA": component.get("v.questionA"), 
                                      "questionB": component.get("v.questionB"),
                                      "questionC": component.get("v.questionC"),
                                      "questionD": component.get("v.questionD"), 
                                      "questionE": component.get("v.questionE"), 
                                      "questionF": component.get("v.questionF"), 
                                      "questionG": component.get("v.questionG"), 
                                      "questionH": component.get("v.questionH"), 
                                      "questionI": component.get("v.questionI"), 
                                      "questionJ": component.get("v.questionJ"), 
                                      "questionK": component.get("v.questionK"), 
                                      "questionL": component.get("v.questionL") 
                                      }
                       function(newComponent, status, errorMessage){
                          if (status === "SUCCESS") {
                            var body = component.find("childQuestion");
                             body.push(body, newComponent);

                          }
                          else if (status === "INCOMPLETE") {
                              console.log("No response from server or client is offline.")
                              // Show offline error
                          }
                          else if (status === "ERROR") {
                              console.log("Error: " + errorMessage);
                              // Show error message
                          }

                          }

                        );

                     }

Is this approach right ?

PS: There is no init method I can use in the Child component.

3
  • This won't work. I really doubt that you want to really recreate a component from scratch. There are usually easier ways to accomplish whatever it is you're trying to do.
    – sfdcfox
    Sep 2, 2017 at 6:02
  • what are you trying to do. Do you want to recreate a new component or just want to refresh component with new attribute values? Sep 2, 2017 at 9:41
  • I just want to refresh with new attribute values.. I was skeptical about refreshing the whole component, but refreshing all the attribute values in the child component is exactly what I need..
    – Brav
    Sep 2, 2017 at 10:23

1 Answer 1

1

If you used a v.questionlist for the array of questions in your parent controller used by the child component, setting the values of that list in the parent controller, should also update the values seen by the child component. You'll want to make certain the attributes are defined properly for the list of questions in the components across your application for that to happen.

There's absolutely no need to destroy and recreate the child component each time your dataset changes.

You must log in to answer this question.

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