Hi,
I am testing Felgo qml json. I set small example but I cannot get the value to show in List View. I need help?
import Felgo 3.0
import QtQuick 2.0
import QtQuick.Controls 1.2
App {
id: appRoot
Page {
id: myPage
anchors.fill: parent
Item {
id: myJson
x: 0
y: 150
width: 300
height: 400
ListModel {
id: model
}
ListView {
id: listview
anchors.fill: parent
model: model
delegate: Text {
color: "red"
text: listdata
}
}
Button {
anchors.bottom: parent.bottom
width: parent.width
text: "Get Data"
onClicked: myPage.getData
}
function getData() {
var xmlhttp = new XMLHttpRequest();
var url = "https://api.ipify.org?format=json"
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState === XMLHttpRequest.DONE && xmlhttp.status === 200) {
myPage.myFunction(xmlhttp.responseText);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function myFunction(response) {
var arr = JSON.parse(response);
for(var i = 0; i < arr.length; i++) {
listview.model.append( {listdata: arr[i].ip })
}
}
}
}
}