You need to sign in to do that
Don't have an account?
badri nath 9
didnt getting response check me once?
component:
<aura:component implements="force:appHostable" controller = "SearchClass">
<aura:attribute name = "search" type = "string" />
<aura:attribute name = "accnts" type ="Account[]" />
<ui:inputText value = "{!v.search}" class = "slds-input" placeholder = "Account Search"/>
<lightning:button onclick = "{!c.search}" name = "btn1" label = "Search"/>
<aura:iteration items = "{!v.accnts}" var = "a" >
<ui:outputText value = "{!a.Id}" />
<ui:outputText value = "{!a.Type}" />
</aura:iteration>
</aura:component>
controller:
({
search : function(component, event, helper) {
var action = component.get("c.getAccounts");
var value1 = component.get("v.search");
//alert(value1);
action.setParam({ "acc" : value1 });
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.accnts" ,response.getReturnValue());
alert("From server: " + response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
serversidecontroller:
public class SearchClass {
@AuraEnabled
public static List<Account> getAccounts(string acc){
string accname ;
accname = acc ;
list<account> actlst = new list<Account>();
actlst = [select Id ,Type from Account where Name = 'accname' ];
return actlst;
}
}
<aura:component implements="force:appHostable" controller = "SearchClass">
<aura:attribute name = "search" type = "string" />
<aura:attribute name = "accnts" type ="Account[]" />
<ui:inputText value = "{!v.search}" class = "slds-input" placeholder = "Account Search"/>
<lightning:button onclick = "{!c.search}" name = "btn1" label = "Search"/>
<aura:iteration items = "{!v.accnts}" var = "a" >
<ui:outputText value = "{!a.Id}" />
<ui:outputText value = "{!a.Type}" />
</aura:iteration>
</aura:component>
controller:
({
search : function(component, event, helper) {
var action = component.get("c.getAccounts");
var value1 = component.get("v.search");
//alert(value1);
action.setParam({ "acc" : value1 });
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.accnts" ,response.getReturnValue());
alert("From server: " + response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
serversidecontroller:
public class SearchClass {
@AuraEnabled
public static List<Account> getAccounts(string acc){
string accname ;
accname = acc ;
list<account> actlst = new list<Account>();
actlst = [select Id ,Type from Account where Name = 'accname' ];
return actlst;
}
}
There are two mistake in your code:
- First: setParams currently you are using setParam
- Secondly: In Apex controller use ":" semicolon notation to populate field. Please use below code:
-
Hope this helps!!!Thanks,
Gaurav
Skype: gaurav62990
All Answers
There are two mistake in your code:
- First: setParams currently you are using setParam
- Secondly: In Apex controller use ":" semicolon notation to populate field. Please use below code:
-
Hope this helps!!!Thanks,
Gaurav
Skype: gaurav62990