0

I would like to get the values of object without aura iteration

let buttonList = tempRes.buttonList;
            var btnObj = [] ;
            if(buttonList){
                buttonList.forEach(function(button){
                    btnObj.push({
                        'label':button.Button_Label__c,
                         'details':{'label':button.Button_Label__c,'textColor':button.Button_Text_Color__c,'Icon':button.Icon__c,'shortCut':button.Shortcut_Keys__c,'bgColor':button.Background_Color__c}
                    })
                })
            }
            component.set("v.btnList",btnObj);

I know to get it through aura:iterator. Is there any alternative?. Please help.

Can I do something like this in aura

const map1 = new Map();
map1.set('bar', {'test':123,'test2':2333});
 map1.set('bar1', 'foo00000');
 if(map1.has('bar')){
  console.log(map1.get('bar').test);
  }

Is this possible?

<aura:if istrue="map1.has('bar'))">
<button value={!map1.get('bar').test}/>
</aura:if>

1 Answer 1

1

No, there is no function in Aura to check if a Map contains a value. Instead, you will need to check for the value in your JavaScript controller or helper (similar to your example with Map.has) and store the value in a way that is referenceable in your component markup.

.js controller or helper

const map1 = new Map();
map1.set('bar', {'test':123,'test2':2333});
map1.set('bar1', 'foo00000');
component.set('v.hasBar', map1.has('bar'));

.cmp

<aura:if isTrue="{!v.hasBar}"
    <p>true outcome</p>
</aura:if>

However, if you need to iterate over results that exist within the Map, you can do that too by taking Map.values() and putting them into an array that <aura:iterate /> can walk over.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .