I have a lightning component with this attribute:
<aura:attribute name="transportData" type="Object[]" access="global"/>
I am getting the data from a http Request:
$.ajax({
url: "https://xxxx/api/transport/",
type: "GET",
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization", "Basic XXXXX");
},
crossDomain: true,
success: function(data){
console.log(data);
component.set("v.transportData", data);
}
});
The console.log gives me data like this example:
{client: "Client01", MTA: "MTA1", Id: 3713, current: 1632679, total: 1845573, …}
In another function I want to get the data from the lightning attribute back and store it in a variable:
var transport = component.get("v.transportData");
But I am always getting an empty array with length of 0.
Funnily enough when I want to get the data in markup, it is showing right:
<aura:iteration items="{!v.transportData}" var="obj">
<span>{!obj.client}</span> //=Client01
</aura:iteration>
Could you tell me what I am doing wrong?