Hello I am creating a lightning component. I have a list of accounts obtained by a query in an apex class. I want to send this list to an array in a javascript controller that will let me assign the record values to variables
Apex:
public with sharing class AccountController
{
@AuraEnabled
public static List<Account> getAccounts()
{
List<Account> Accounts = [SELECT Id, Name FROM Account];
return Accounts;
}
}
JavaScript controller:
doInit: function(component, event, helper)
{
///Obtain account record list from Apex SOQL and pass it to an array.
//var records = [] ???
//This list is what will be passed to lightning component when function ends.
var newItems=[];
//Loop through records array and create item list using record field values.
for (var i=0; i< records.length; i++)
{
var record = records[i];
var Item = {title: record.name, id: record.id, status: "Unassigned"};
newItems.push(Item);
}
//Pass items into component
component.set("v.allItems", newItems);
},