Component Body is empty after init event but not from Chrome Console

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I've a weird behaviour going on here. I've built a custom card carousel component as below :



<c:carouselComponent aura:id="carousel"
iconName="standard:carousel"
title="Cards"
showTotal="true">

<aura:iteration aura:id="iterator" items="!v.data" var="content">
<c:carouselCardComponent
title="!content.title"
imageSrc="!content.thumbnail"
>
</c:carouselCardComponent>
</aura:iteration>

</c:carouselComponent>


And this is what happens from c:carouselComponent controller in init handler :



onInit: function(component, event, helper) {
var body = component.get('v.body');
var cards = ;

body.forEach(function(el)
if (el.getLocalId() === 'iterator')
console.log(el.get('v.body'));
var children = el.get('v.body');
cards = children;

else
cards.push(el);

);
...


Nothing is actually showing in the carousel because the carouselComponent body seems to be empty after it's rendered : console.log(el.get('v.body')) returns an empty array.



But when i visualize the el object directly from Chrome Console, el.get('v.body') is not an empty array but it contains all the objects created by the aura:iteration component .



What is actually happenning? i think i'm missing something and i don't know how to figure it out.



Thank you for any idea!










share|improve this question



























    up vote
    2
    down vote

    favorite












    I've a weird behaviour going on here. I've built a custom card carousel component as below :



    <c:carouselComponent aura:id="carousel"
    iconName="standard:carousel"
    title="Cards"
    showTotal="true">

    <aura:iteration aura:id="iterator" items="!v.data" var="content">
    <c:carouselCardComponent
    title="!content.title"
    imageSrc="!content.thumbnail"
    >
    </c:carouselCardComponent>
    </aura:iteration>

    </c:carouselComponent>


    And this is what happens from c:carouselComponent controller in init handler :



    onInit: function(component, event, helper) {
    var body = component.get('v.body');
    var cards = ;

    body.forEach(function(el)
    if (el.getLocalId() === 'iterator')
    console.log(el.get('v.body'));
    var children = el.get('v.body');
    cards = children;

    else
    cards.push(el);

    );
    ...


    Nothing is actually showing in the carousel because the carouselComponent body seems to be empty after it's rendered : console.log(el.get('v.body')) returns an empty array.



    But when i visualize the el object directly from Chrome Console, el.get('v.body') is not an empty array but it contains all the objects created by the aura:iteration component .



    What is actually happenning? i think i'm missing something and i don't know how to figure it out.



    Thank you for any idea!










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I've a weird behaviour going on here. I've built a custom card carousel component as below :



      <c:carouselComponent aura:id="carousel"
      iconName="standard:carousel"
      title="Cards"
      showTotal="true">

      <aura:iteration aura:id="iterator" items="!v.data" var="content">
      <c:carouselCardComponent
      title="!content.title"
      imageSrc="!content.thumbnail"
      >
      </c:carouselCardComponent>
      </aura:iteration>

      </c:carouselComponent>


      And this is what happens from c:carouselComponent controller in init handler :



      onInit: function(component, event, helper) {
      var body = component.get('v.body');
      var cards = ;

      body.forEach(function(el)
      if (el.getLocalId() === 'iterator')
      console.log(el.get('v.body'));
      var children = el.get('v.body');
      cards = children;

      else
      cards.push(el);

      );
      ...


      Nothing is actually showing in the carousel because the carouselComponent body seems to be empty after it's rendered : console.log(el.get('v.body')) returns an empty array.



      But when i visualize the el object directly from Chrome Console, el.get('v.body') is not an empty array but it contains all the objects created by the aura:iteration component .



      What is actually happenning? i think i'm missing something and i don't know how to figure it out.



      Thank you for any idea!










      share|improve this question













      I've a weird behaviour going on here. I've built a custom card carousel component as below :



      <c:carouselComponent aura:id="carousel"
      iconName="standard:carousel"
      title="Cards"
      showTotal="true">

      <aura:iteration aura:id="iterator" items="!v.data" var="content">
      <c:carouselCardComponent
      title="!content.title"
      imageSrc="!content.thumbnail"
      >
      </c:carouselCardComponent>
      </aura:iteration>

      </c:carouselComponent>


      And this is what happens from c:carouselComponent controller in init handler :



      onInit: function(component, event, helper) {
      var body = component.get('v.body');
      var cards = ;

      body.forEach(function(el)
      if (el.getLocalId() === 'iterator')
      console.log(el.get('v.body'));
      var children = el.get('v.body');
      cards = children;

      else
      cards.push(el);

      );
      ...


      Nothing is actually showing in the carousel because the carouselComponent body seems to be empty after it's rendered : console.log(el.get('v.body')) returns an empty array.



      But when i visualize the el object directly from Chrome Console, el.get('v.body') is not an empty array but it contains all the objects created by the aura:iteration component .



      What is actually happenning? i think i'm missing something and i don't know how to figure it out.



      Thank you for any idea!







      lightning-components






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Bryce

      566




      566




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          aura:valueInit is always the first event fired in the rendering life cycle for new components, before anything else happens, including rendering anything inside aura:iteration. You'd have to wait until at least the first rendering cycle completes. You should be able to simply do something like the following:



          setTimeout(
          $A.getCallback(
          function()
          helper.postRenderHandler(component, event, helper);

          )
          );


          You might also get away with registering an aura:valueChange handler on the body attribute, but you'll have to be careful to avoid infinite recursion.






          share|improve this answer
















          • 2




            The article you linked to explains how to run code after the rendering is completed. Is there a reason you recommend setTimeout instead of handling the render event as stated in the article?
            – gNerb
            33 mins ago






          • 1




            @gNerb because it requires a full render cycle. The components will not exist any time during the first render cycle. This is a pecularity of aura:iteration, which performs its own rendering later.
            – sfdcfox
            23 mins ago










          • Thank you @sfdcfox
            – gNerb
            18 mins ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f236198%2fcomponent-body-is-empty-after-init-event-but-not-from-chrome-console%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote













          aura:valueInit is always the first event fired in the rendering life cycle for new components, before anything else happens, including rendering anything inside aura:iteration. You'd have to wait until at least the first rendering cycle completes. You should be able to simply do something like the following:



          setTimeout(
          $A.getCallback(
          function()
          helper.postRenderHandler(component, event, helper);

          )
          );


          You might also get away with registering an aura:valueChange handler on the body attribute, but you'll have to be careful to avoid infinite recursion.






          share|improve this answer
















          • 2




            The article you linked to explains how to run code after the rendering is completed. Is there a reason you recommend setTimeout instead of handling the render event as stated in the article?
            – gNerb
            33 mins ago






          • 1




            @gNerb because it requires a full render cycle. The components will not exist any time during the first render cycle. This is a pecularity of aura:iteration, which performs its own rendering later.
            – sfdcfox
            23 mins ago










          • Thank you @sfdcfox
            – gNerb
            18 mins ago














          up vote
          4
          down vote













          aura:valueInit is always the first event fired in the rendering life cycle for new components, before anything else happens, including rendering anything inside aura:iteration. You'd have to wait until at least the first rendering cycle completes. You should be able to simply do something like the following:



          setTimeout(
          $A.getCallback(
          function()
          helper.postRenderHandler(component, event, helper);

          )
          );


          You might also get away with registering an aura:valueChange handler on the body attribute, but you'll have to be careful to avoid infinite recursion.






          share|improve this answer
















          • 2




            The article you linked to explains how to run code after the rendering is completed. Is there a reason you recommend setTimeout instead of handling the render event as stated in the article?
            – gNerb
            33 mins ago






          • 1




            @gNerb because it requires a full render cycle. The components will not exist any time during the first render cycle. This is a pecularity of aura:iteration, which performs its own rendering later.
            – sfdcfox
            23 mins ago










          • Thank you @sfdcfox
            – gNerb
            18 mins ago












          up vote
          4
          down vote










          up vote
          4
          down vote









          aura:valueInit is always the first event fired in the rendering life cycle for new components, before anything else happens, including rendering anything inside aura:iteration. You'd have to wait until at least the first rendering cycle completes. You should be able to simply do something like the following:



          setTimeout(
          $A.getCallback(
          function()
          helper.postRenderHandler(component, event, helper);

          )
          );


          You might also get away with registering an aura:valueChange handler on the body attribute, but you'll have to be careful to avoid infinite recursion.






          share|improve this answer












          aura:valueInit is always the first event fired in the rendering life cycle for new components, before anything else happens, including rendering anything inside aura:iteration. You'd have to wait until at least the first rendering cycle completes. You should be able to simply do something like the following:



          setTimeout(
          $A.getCallback(
          function()
          helper.postRenderHandler(component, event, helper);

          )
          );


          You might also get away with registering an aura:valueChange handler on the body attribute, but you'll have to be careful to avoid infinite recursion.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 59 mins ago









          sfdcfox

          233k10179395




          233k10179395







          • 2




            The article you linked to explains how to run code after the rendering is completed. Is there a reason you recommend setTimeout instead of handling the render event as stated in the article?
            – gNerb
            33 mins ago






          • 1




            @gNerb because it requires a full render cycle. The components will not exist any time during the first render cycle. This is a pecularity of aura:iteration, which performs its own rendering later.
            – sfdcfox
            23 mins ago










          • Thank you @sfdcfox
            – gNerb
            18 mins ago












          • 2




            The article you linked to explains how to run code after the rendering is completed. Is there a reason you recommend setTimeout instead of handling the render event as stated in the article?
            – gNerb
            33 mins ago






          • 1




            @gNerb because it requires a full render cycle. The components will not exist any time during the first render cycle. This is a pecularity of aura:iteration, which performs its own rendering later.
            – sfdcfox
            23 mins ago










          • Thank you @sfdcfox
            – gNerb
            18 mins ago







          2




          2




          The article you linked to explains how to run code after the rendering is completed. Is there a reason you recommend setTimeout instead of handling the render event as stated in the article?
          – gNerb
          33 mins ago




          The article you linked to explains how to run code after the rendering is completed. Is there a reason you recommend setTimeout instead of handling the render event as stated in the article?
          – gNerb
          33 mins ago




          1




          1




          @gNerb because it requires a full render cycle. The components will not exist any time during the first render cycle. This is a pecularity of aura:iteration, which performs its own rendering later.
          – sfdcfox
          23 mins ago




          @gNerb because it requires a full render cycle. The components will not exist any time during the first render cycle. This is a pecularity of aura:iteration, which performs its own rendering later.
          – sfdcfox
          23 mins ago












          Thank you @sfdcfox
          – gNerb
          18 mins ago




          Thank you @sfdcfox
          – gNerb
          18 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f236198%2fcomponent-body-is-empty-after-init-event-but-not-from-chrome-console%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          Installing NextGIS Connect into QGIS 3?

          One-line joke