2

Salesforce lightning component:

  1. I'm trying to solve an issue of accessing an object's field dynamically - e.g. obj.get(fieldAPI);

  2. After trying numerous workarounds I decided to try and Id div's uniquely and then with jQuery to populate these. E.g. .

  3. I have the correct code to update the div, BUT when I run the script while INIT the DOM is not ready yet [Its undefined to be accurate].

  4. Any idea how to work out these please?

Cheers!

  • Any reason why the answer below has not been accepted? please consider doing so so it may help others. Thanks – glls Feb 22 '18 at 23:13
3

If you need to wait until after the DOM is available, then you should use a renderer.

The afterRender event fires after the DOM is ready. You can then use this to assign values, modify DOM.

First you will need a function in your lightning component's helper:

{
  postRender : function(component){
    //...do some stuff here...
  }
{

Second you need to have to call this from the renderer:

({
  afterRender: function(component, helper) {
    this.superAfterRender();
    helper.postRender(component);
  }
})

Normally you don't want to use renderers for arbitrary assigning values as this is what the attribute binding is intended to accomplish. But in this case where you are dynamically assigning which fields will even be present based on object...this sounds like a good use case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.