0

Was wondering if it is possible to use a string component attribute to target defined javascript variables.

This is what i am looking to do

var owner = initial[i].Policy_Owner__c ? initial[i].Policy_Owner__r.Name : "Awaiting Owner"

var policy = initial[i].Insurance_Carrier__c initial[i].Insurance_Carrier__r.Name : "Carrier Not Listed"

saver.push(component.get('v.sortedby'));

sortedby is a string attribute. There is definitely a workaround for this particular situation but i am more wondering on the general concept of how to use component attributes to dynamically target javascript variables

2

You'd use an Object if you wanted to select a specific element, like this:

var values = {
  owner: initial[i].Policy_Owner__r.Name || 'Awaiting Owner',
  policy: initial[i].Insurance_Carrier__r.Name || 'Carrier Not Listed'
}, sortedBy = component.get('v.sortedBy');
saver.push(values[sortedBy]);

This method of dynamically choosing a value falls under Property accessors.


In "normal" JavaScript, we could also just "eval", but this is specifically disallowed in Aura in order to prevent developers bypassing Locker Service security features.

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.