I have this below code where i am trying to first search an account name and on hit button it displays the result set which is currently working for me.
Now i have an tag on the records displayed. On click of the record i need to write in debug console.
Can anyone let me know how i can do it. In the below code i am trying , but i am not getting it.
Component -
<aura:component controller="SimpleAccountController">
<aura:attribute name="account" type="account[]"/>
<ui:outputText aura:id="outName" value="" class="text"/>
<ui:inputText aura:id="name" label="Enter Name:" placeholder="Your Name" />
<ui:button aura:id="button" buttonTitle="Click to see what you put into the field" class="button" label="Click me" press="{!c.getInput}"/>
<aura:iteration var="acc" items="{!v.account}">
<a onclick="{!c.accountselected}" data-recId="{!acc.Id}">
<p>{!acc.Name} : {!acc.Type} : {!acc.Industry} : {!acc.Rating}</p>
</a>
</aura:iteration>
</aura:component>
Controller -
({
getInput : function(cmp, evt) {
var myName = cmp.find("name").get("v.value");
var myText = cmp.find("outName");
var greet = "Hi, " + myName;
myText.set("v.value", greet);
var action = cmp.get("c.seaAcc");
action.setParams({ "s" : myName });
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.account", response.getReturnValue());
//alert("From server: " + response.getReturnValue());
}
});
$A.enqueueAction(action);
},
accountselected : function(cmp, evt) {
console.log(evt.target.getAttribute("data-recId")) ;
}
})