I'm trying to pass a list of string from Apex controller to Javascript but it does not seem to work
Code I tried:
Apex class
@AuraEnabled
public static List<String> getGroups(){
string names;
List<String> Groupnames = new List<String>();
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setMethod('GET');
request.setHeader('X-ChatWorkToken',key);
request.setEndpoint('https://api.chatwork.com/v2/rooms');
HttpResponse res = http.send(request);
LIST<Object> arr = (LIST<Object>) JSON.deserializeUntyped(res.getBody());
for(integer i = 0; i < arr.size(); i++){
Map<String, Object> firstMap = (Map<String, Object>)arr[i];
names = (String)firstMap.get('name');
Groupnames.add(names);
}
return Groupnames;
}
Javascript
listofgroup:function(component, event, helper){
var action = component.get("c.getGroups");
console.log('received',response);
action.setCallback(this, function(response){
//var state = response.getState();
// if(state === 'SUCCESS'){
var res = response.getReturnValue();
for(var i = 0; i < res.length; i++){
//set the values here
component.set("v.lstGroup",response.getReturnValue());
}
}
// }
)
}
dont know where I'm going wrong