Can someone please explain to me what I am doing wrong with the following setup.
The idea is to develop the game engine in engine.js and the UI logic is in the qml file.
page.qml
Page {
id: page
SilicaGridView {
id: listView
model: ListModel {
id: roleList
Component.onCompleted: {
Engine.addRoles(roleList);
}
}
delegate: Rectangle {
id: delegate
border.color: model.selected ? Theme.highlightColor : Theme.primaryColor
Label {
text: qsTr(model.name)
}
MouseArea {
anchors.fill: parent;
onClicked: {
Engine.selectRole(model);
}
}
}
}
}
engine.js:
function Role() {
this.name = "role"
this.selected = false;
}
function addRoles(list) {
list.append(new Role());
list.append(new Role());
}
function selectRole(role) {
console.log(role.selected) // <-- false
role.selected = true;
console.log(role.selected) // <-- false
}
So when I click an element on the page, it calls selectRole from the engine. For some weird reason updating the selected property on the model does not actually update the model. Why is it like this?