Ok, for some reason, it did work, so this is a part of my app-qml:
Code: Select all
App {
id: root
property variant devices : []
property bool devicesReceived: false
property string username: "username"
property string password: "password"
function getDevices() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var res = JSON.parse(xmlhttp.responseText);
devices = res["result"]
for (var p in devices){
console.log("Device: "+p + ": " + devices[p]['Name']);
}
devicesReceived = true;
}
}
}
xmlhttp.open("GET", "http://192.168.1.3:8084/json.htm?username="+username+"&password="+password+"&type=devices&favorite=1&filter=all&used=true&order=Name", true);
xmlhttp.send();
}
}
In my screen-qml, i have to following:
Code: Select all
Repeater {
id: switches
model: app.devices
SwitchItem {
idx: model['idx']
title: model['Name']
status: model['Data']
lastupdate: model['LastUpdate']
}
}
In the console.log in the first part of my code above, I get:
Device: 0 : Woonkamer
Device: 1 : Slaapkamer
BUT, for some reason, the variables are undefined (like: model['Name']) in the Repeater (I refer to app.devices in the model-argument, the devices-variable in my app-qml)
EDIT, SOLVED!!!!!
Code: Select all
SwitchItem {
idx: app.devices[index]['idx']
title: app.devices[index]['Name']
status: app.devices[index]['Data']
lastupdate: app.devices[index]['LastUpdate']
}