我有一個ListView,它顯示一個用戶的所有通知的串列。現在,由于我使用Component.onCompleted,如果串列更新,新的串列不會被顯示,而是顯示實體化時存在的那個。我們怎樣才能解決這個問題呢?使用一個帶有獨立組件的加載器會有幫助嗎?
property int numNotifications: backend_service.num_notifications
屬性var notifications。[]
onNumNotificationsChanged: {
for(var x=0; x<numNotifications; x ) {
var notif = backend_service.notifications.get(x);
Notifications.push(notif)
}
}
矩形 {
anchors.horizontalCenter: parent.horizontalCenter
顏色:"black"。
高度。500
寬度: 0.95 * parent.width
串列視圖 {
anchors.fill: parent
模型:notifModel
委托:notifDelegate
}
}
ListModel {
id: notifModel
Component.onCompleted: {
for(var i in notifications) {
notifModel.append({"name"/span>: notifications[i]})
}
}
}
組件 {
id: notifDelegate
行 {
間隔。10
Text { text: name; color: "white" }
}
}
uj5u.com熱心網友回復:
Component.onCompleted只在物件被構建時運行,而不會再運行。所以使用該方法向模型添加專案是沒有用的,相反,你應該使用報告新資料的函式:
onNumNotificationsChanged: {
for(var x=0; x<numNotifications; x ) {
var notif = backend_service.notifications.get(x)。
notifModel.append({"name"/span>: notif})
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/310185.html
標籤:
