0

I have been reading and I can't seem to understand one part of the component - controller - helper - apex combo.

If I have a lightning component that is connected to an apex controller...I am confused how an attribute such as <aura:attribute name="ahg" type="object" /> would know any data. Where is it pulling the data from? What is the value of agh? I can see from a console.log that ahg has a value. I just don't understand how it is set.

Secondly, what is the value of parameters component, event, helper in the lightning component's controller's function? Is the param component the object? Is there an easy way to console.log() the event? Right now I get back [Object, Object]. When I: event.toString() or console.dir() I get back useless information.

My end goal is to get the value of a custom object's name and hid/display a div dependent on the value. I need to be able to see the values and know what I am playing with so that I can then pass the appropriate data to the apex controller (if needed).

Component

<aura:component controller="CommunityAccountListController" implements="forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="ahg" type="object" />

Controller

({
    doInit : function(component, event, helper) {

enter code here

  • It seems you are missing relevant code in your post. – Jayant Das Feb 12 at 23:14
  • With the information you have in your post as of now, take a look at this documentation which should clarify your question on the JS controller. – Jayant Das Feb 12 at 23:15
3

Ok, I see two questions here:

1) Where are the attribute values coming from

The value of an aura:attribute can really come from four places

  • It can be set in javascript component.set('v.ahg', myVariable)
  • It can be passed as a parameter to the component <c:myComponent ahg="myValue" />
  • It can be defined by default in the attribute <aura:attribute name="ahg" type="String" value="a String">
  • it can come from the flexipage itself (via a Design Attribute)

More details here. It's hard to apply this to your use case. I don't have enough detail to dig more

2) What are the values of component, event, helper

The three values contain, in order,

  • a reference to the component JS. You would use this for various things, like setting/getting attribute values (see my example above) or finding nodes by their "aura:id" (component.find('myComponentId'))
  • a reference to the event being fired, if any. You would use this to catch events and their parameters (event.getParam('myValue'))
  • a reference to the helper JS You would use this to call helper functions (helper.doSomething())

There are a bazillion more uses for the three classes, but these are basics of what you can do with each. You can start here and read the documentation from there.

  • this is super helpful thank you. I found where ahg was being set, so this makes sense now. For tapping into the component parameter, is there a way to pull out values by walking up or down the relationships inside of it? Component is a wrapper of an Account record and a custom object record. See attached picture. – Olivia Feb 12 at 23:54
  • Yes, you can. Get the value into a JS variable and then you use it as anything else. – Sebastian Kessel Feb 13 at 0:19
  • 1
    @SebastianKessel +1 although: "value ... can come from three places" It can also come from the App Builder via a Design Attribute (for supported data types). – sfdcfox Feb 13 at 1:21
  • @sfdcfox I knew I was going to miss one. Will update for future readers. – Sebastian Kessel Feb 13 at 5:00

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.