You need to sign in to do that
Don't have an account?
The proper way to refer to sObject fields in Lightning Component/JS
What is the proper way to refer to fields on an sobject in your JS controller? Assuming I have an attribute "salesCall" of type "Sales_Call__c", is it....
or
The former seems intuitive - console.log() the salesCall var and you get a JSON object - but is giving me radically wonky and inconsistent results. Sometimes I get a value, sometimes I get undefined, even though the JSON object has it. And forget about trying to actually set a value on it.
The latter method seems to perform more consistently and I'm getting much better results with that.
But is there a technical reason why the former won't work? Some thing to do with Aura's data binding?
var salesCall = component.get('v.salesCall'); console.log(salesCall.myField);
or
console.log( component.get('v.salesCall.myField') );
The former seems intuitive - console.log() the salesCall var and you get a JSON object - but is giving me radically wonky and inconsistent results. Sometimes I get a value, sometimes I get undefined, even though the JSON object has it. And forget about trying to actually set a value on it.
The latter method seems to perform more consistently and I'm getting much better results with that.
But is there a technical reason why the former won't work? Some thing to do with Aura's data binding?
...does not really work at all, but ...
...does.
However, if I ask for component.get('v.salesCall.Some_Field__c'), then I get the value as it stands in the input field.
I don't know the inner workings of the Aura framework, but I'm guessing that
...and...
...are distinct and unique from each other. Those are string keys after all, even if it looks like dot notation. They're separate from each other and updating one doesn't update the other until later in Aura's rendering cycle...or something. I'm just guessing at this point! :P