Reputation: 78
Can't create an object on the list.
I need the recent requests to be displayed in the "Recent" list. After submitting, I store the request in the listOfRecents array.
The problem is that I cannot create a list object by taking data from that array. Below are the pieces of code and the error.
Here's the code with the list:
Page {
id: serv
title: qsTr("Recent")
function addRecent()
{
inRecentList.clear()
for(var i = 0; i < listOfRecents.length; ++i)
{
var temp = listOfRecents[i];
inRecentList.append({inningData: listOfRecents[i],
inningShow: listOfRecents[i]})
temp = inRecentList[i].inningData
temp = ""
}
}
Component.onCompleted: {
addRecent()
}
ListView {
id: inRecent
x: 5
y: 5
width: parent.width - 10
height: parent.height - 50
spacing: 2
delegate: RecentItem {
isData: inningData
isShow: inningShow
}
model: ListModel {
id: inRecentList
}
}
}
Here is the RecentItem code:
Item {
id: inning
property string isShow: ""
property string isData: ""
height: 32
width: inRecent.width
Button
{
height: parent.height
width: parent.width
Row {
anchors.fill: parent
spacing: 10
Image {
id: img
source: "Res/images/ui_elements/query.png"
}
Text {
text: isShow
font{
bold: true
italic: true
pixelSize: 24
}
}
}
onClicked: {
stackView.pop()
stackView.pop()
sTextToRecent(isData)
}
}
}
It gives the following error in the console:
qrc:/Recent.qml:19: TypeError: Cannot read property 'inningData' of undefined
qrc:/Recent.qml:41: ReferenceError: inningShow is not defined
qrc:/Recent.qml:40: ReferenceError: inningData is not defined
Upvotes: 0
Views: 252
Reputation: 8277
I believe the only thing you're missing is that you're trying to read from the model incorrectly. Instead of this:
temp = inRecentList[i].inningData
do this:
temp = inRecentList.get(i).inningData
Upvotes: 2