Component:
<aura:attribute name="String" type="String[]"/>
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:card title="Filtered Values">
<div class="search-field">
<lightning:input aura:id="nameFilter" label="Filter names" onchange="{!c.handleNameFilterChange}" />
</div>
<!--
<div class="results">
<aura:if isTrue="{!v.contacts.length > 0}">
<p class="has-results">
Showing {!v.contacts.length} contact(s):
</p>
<ol class="slds-list_dotted">
-->
<ol>
<aura:iteration items="{!v.String}" var="s">
<li>
<a id="getId" onclick="{!c.handleClick}">
{!s}
</a>
</li>
</aura:iteration>
</ol></lightning:card></aura:component>
controller
helper({
init: function(component, event, helper) {
helper.loadList(component);
},
handleNameFilterChange: function (component, event, helper) {
helper.loadList(component);
},
})
({
loadList: function(component) {
var action = component.get("c.allContacts");
var nameFilterString = component.find("nameFilter").get("v.value");
action.setParams({
nameFilterString: nameFilterString
});
action.setCallback(this, function(a) {
component.set("v.String", a.getReturnValue());
});
$A.enqueueAction(action);
}
})
thanks,
Hi Agnibha,First of all, you have to remove id attribute from anchor tag, as we don not user static id in the iteration.You will also need to add a custom attribute to get the value of the selected anchor tag. <aura:component implements="flexipage:availableForAllPageTypes" access="global" >
<aura:attribute name="String" type="String[]"/>
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:card title="Filtered Values">
<div class="search-field">
<lightning:input aura:id="nameFilter" label="Filter names" onchange="{!c.handleNameFilterChange}" />
</div>
<!--
<div class="results">
<aura:if isTrue="{!v.contacts.length > 0}">
<p class="has-results">
Showing {!v.contacts.length} contact(s):
</p>
<ol class="slds-list_dotted">
-->
<ol>
<aura:iteration items="{!v.String}" var="s">
<li>
<a onclick="{!c.handleClick}">
{!s}
</a>
</li>
</aura:iteration>
</ol>
</lightning:card>
</aura:component>
You have to define an method called handleClick for capturing anchor tag value and assign into the input box.
If you found it useful please appreciate my efforts and mark it as the best answerThanks,Soyab({
init: function(component, event, helper) {
helper.loadList(component);
},
handleNameFilterChange: function (component, event, helper) {
helper.loadList(component);
},
handleClick: function (component, event, helper) {
alert(event.currentTarget.dataset.item);
component.find("nameFilter").set("v.value",event.currentTarget.dataset.item)
},
})