I am trying to get weather (wx) info from Region Weather list and and wxicon from another list. For List from Region Weather I can get it, For List from wxicon I could not get it. I attempted to use the same qurl in getIcon(), but my variable shows undefine.
What would caused it?
function to get wx info
private getWx(){
var qurl;
qurl="/_api/web/lists/getbytitle('Region Weather')/items?$select=*,AttachmentFiles&$expand=AttachmentFiles/Title&$top=1";
const opt: ISPHttpClientOptions = { headers: { 'Content-Type': 'application/json;odata=verbose' } };
this.props.SPHttpClient.get(this.props.pagecontext.web.absoluteUrl + qurl, SPHttpClient.configurations.v1,opt)
.then((response: SPHttpClientResponse) => {
response.json().then((json: any) => {
for(let i=0;i<json.value.length;i++){
var icon;
// icon=this.getIcon(json.value[i].Conditions);
icon="https://icons-for-free.com/iconfiles/png/512/forecast+partly+cloudy+weather+icon-1320196484400215944.png";
this.data.push({
city:json.value[i].Title,
condition:json.value[i].Conditions,
temp:json.value[i].Temperature,
atemp:json.value[i].Apparent_x0020_Temperature,
unit:json.value[i].Temperature_x0020_Unit,
icon:icon,
});
this.forceUpdate();
}
//this.setState({wx:this.data});
});
});
}
- function to get wx icon from another list
private getIcon(condition){
var iconq;
var temp;
iconq="/_api/web/lists/getbytitle('wxicon')/items?$select=*,AttachmentFiles&$expand=AttachmentFiles/Title&$top=1";
const opt: ISPHttpClientOptions = { headers: { 'Content-Type': 'application/json;odata=verbose' } };
this.props.SPHttpClient.get(this.props.pagecontext.web.absoluteUrl + iconq, SPHttpClient.configurations.v1,opt)
.then((response: SPHttpClientResponse) => { debugger;
response.json().then((json: any) => {
for(let i=0;i<json.value.length;i++){
debugger;
temp=json.value.Title ;
}
});
});
debugger;
return temp;
}