Hi,
My json’ gets 6 data always. But, I can show only first data. I am not be able to show rest of the data.
Somewhere in my code something is missing. How do I show all the data in qml? Any help please?
import Felgo 3.0
import QtQuick 2.9
import QtQuick.Layouts 1.3
import "../singletons"
Item {
id: myWeatherItem
anchors.horizontalCenter: parent.horizontalCenter
width: CbStyle.appWidth - 25
height: CbStyle.appHeight * 0.27
anchors.leftMargin: dp(5)
anchors.rightMargin: dp(5)
AppListView {
id: weatherView
anchors.fill: parent
backgroundColor: "#00000000"
model: ListModel { id: modelData }
delegate: Item {
id: myDelegate
width: Math.max(110, myWeatherItem.width / weatherView.count)
height: myWeatherItem.height
// Content
ColumnLayout {
anchors.fill: parent
anchors.topMargin: 10
anchors.bottomMargin: 10
// day
Text {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: model.day
}
// icon
Image {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
scale: 0.75
source: model.iconText
}
// temperature
Text {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: "%1˚C".arg(model.temperature)
}
// seperator
Rectangle {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
width: 1
height: (myWeatherItem.height * 0.75)
color: "lightgrey"
// visible: model.index < weatherView.count - 1
}
} // Contents
} // delegate: Item
Component.onCompleted: {
var request = new XMLHttpRequest();
request.open('GET', "https://query.*****************************", true);
request.onreadystatechange = function() {
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status && request.status === 200) {
var result = JSON.parse(request.responseText)
var list = result.query.results.channel.item.forecast //result[0]["forecast"];
for(var i in list) {
var getStatusIcon = list[i].code
modelData.append({ "day": list[i].day,
"iconText": "../../assets/weather/" + getStatusIcon + ".png",
"temperature": list[i].high
});
console.log(i + ", Day:" + list[i].day + ", Temp:" + list[i].high + ", CurrentIconSet: " + getStatusIcon)
getStatusIcon = ""
} // for
}
else {
console.log("WeatherLog:", request.status, request.statusText)
}
} // if (request.readyState
} // function
request.send();
}
} // WeatherWidget
} // myWeatherItem