0

Here is my component:

<aura:attribute name="showA" type="String" default="admin" /> 
<aura:attribute name="showB" type="String" default="help" /> 


<a href="#" data-show="{!v.showP}" onclick="{!c.show}" id="New">Link1<a/>
<a href="#" data-showQ="{!v.showQ}" onclick="{!c.show}"  id="Sent">Link2<a/>

Now, whenever a user will click I will get the value of op and op2, but what I want is to use a single attribute and change the value according to the link.

show: function(component,event,helper) {

    var op = event.currentTarget.dataset.show;

    var op2 = event.currentTarget.dataset.showQ; 

    alert(conole.log(op +':::::::::'+ op2));
}

2 Answers 2

2

Below is one way of using a single attribute and setting values for it

Component:

 <aura:attribute name="show" type="String" default="help" /> 
  <a href="#" data-show="{!v.showP}" onclick="{!c.show}" id="New">Link1</a>
<a href="#" data-showQ="{!v.showQ}" onclick="{!c.show}"  id="Sent">Link2</a>

Controller:

show:function(component,event,helper) {
    var op = event.currentTarget.id;
    if(op === 'New') 
    component.set('v.show', 'A');
     if(op === 'Sent')
    component.set('v.show', 'B');
    alert(console.log( component.get('v.show')));
}
0

Firstly you dont need two data-set reference I mean data-show="{!v.showP}" and data-showQ="{!v.showQ}"
simply you can refer data-show on both link data-show="{!v.showP}" and data-show="{!v.showQ}"

In controller you dont need to get it from op and op2 variable. If you want to set to single attribute regarding the value getting according to the link simply In your markup include <aura:attribute name="show" type="String" />

({
    show : function(component, event, helper) {
        var op = event.currentTarget.dataset.show;
        component.set('v.show',op);//set here the value according to the link clicked
    }
})

You must log in to answer this question.

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