You need to sign in to do that
Don't have an account?
Govindaraj
Issue in populating lightning:select
Hi,
I'm getting empty list when trying to populate using server call.
Component:
Can anyone pls assist on this ?
I'm getting empty list when trying to populate using server call.
Component:
<aura:component controller="Picklistcontroller" implements="force:appHostable" > <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <!-- <aura:attribute name="listOfAccount" type="string[]" default="Account1, Account2" /> --> <aura:attribute name="listOfAccount" type="string[]" /> <aura:attribute name="selectedAccount" type="string" /> <lightning:select name="accountList" label="List Of Accounts:" value="{!v.selectedAccount}" onchange="{!c.onChangeEvent}"> <aura:iteration items="{!v.listOfAccount}" var="varAccount" > <option label="{!varAccount.label}" value="{!varAccount.value}"></option> </aura:iteration> </lightning:select> </aura:component>Controller:
({ doInit : function(component, event, helper) { var action = component.get("c.getAccountValues"); var opts = []; action.setCallback(this, function(response) { var state = response.getState(); if(state == 'SUCCESS') { var lstAccount = response.getReturnValue(); console.log('lstAccount-->' +JSON.stringify(lstAccount)); for (var i = 0; i < lstAccount.length; i++) { opts.push({ label: lstAccount[i].Name, value: lstAccount[i].Id }); } component.set('v.listOfAccount', opts); console.log('listOfAccount-->' +JSON.stringify(opts)); } }); $A.enqueueAction(action); }, onChangeEvent : function(component, event, helper) { alert(component.get('v.selectedAccount')); } })Apex class:
public class Picklistcontroller { @AuraEnabled public static list<string> getAccountValues(){ list<String> lstStringAccount = new list<String>(); for(Account accObj : [SELECT Id, Name FROM Account Limit 10]) { lstStringAccount.add(string.valueOf(accObj)); } return lstStringAccount; } }Screenshot:
Can anyone pls assist on this ?
All Answers
But i want to return it as list<string> instead of list<Account>