I have a ListView with a list of JavaScript objects as a model. The delegate needs to respond to click and I want to store click handler attached to model item (action property):
ListView {
id: idListView
model: [
{
name: "Item 1",
icon: "icon1.svg",
action: function() {
//do stuff
}
},
/* other items */
]
delegate: MyDelegate {
name: modelData.name
icon: modelData.icon
MouseArea {
anchors.fill: parent
onClicked {
modelData.action()
}
}
}
}
But when I click on an item i get
TypeError: Property 'action' of object [object Object] is not a function
What's the proper way to attach function to object and call it?