从 SimpleRow 的选定日期设置 calendar.selectedDate
Setting calendar.selectedDate from the Selected Date of a SimpleRow
我在从 listView 中选择日期时打开日历弹出窗口 helpItem1
,一切正常!我想做的是每次选择不同的列表项时将 calendar.selectedDate
设置为 listView
项的日期。
我用来创建 listView
的数组 (userModel
) 的摘录是:
{"date":1551960000000, "name": user1},{"date":1552046400000, "name": user1},{"date":1552219200000, "name": user1}
我的代码的最小部分是:
ListPage {
id: userPage
model: userModel
delegate: SimpleRow {
id: userRow
width: userPage.width
text: modelData.name
detailText: new Date(modelData.date).getTime()
onSelected: {
helpItem1.visible = true
calendar.selectedDate = new Date(modelData.date).getTime()
}
}
Item {
id: helpItem1
visible: false
Rectangle {
id: calendarPage
anchors.centerIn: parent
width: parent.width
height: parent.height
AppButton {
id: backButton
onClicked: {
helpItem1.visible = false
}
//Button used to close the `helpItem1` pop-up
}
Flow {
id: row
Calendar {
id: calendar
focus: true
selectedDate: new Date()
}
// Rest of calendar Code
}
}
}
}
我的问题是:
我如何获取每个 SimpleRow
项目的选定日期,并在弹出窗口打开时将其设置为 calendar.selectedDate
?
我尝试了
的几种变体
SimpleRow.onSelected: {calendar.selectedDate = new Date(modelData.date).getTime()}
但没有任何帮助。
在调整后的 9 分钟内,我想通了:
从我的 onSelected {...}
部分中删除 .getTime()
一切正常!
onSelected: {
helpItem1.visible = true
calendar.selectedDate = new Date(modelData.date)
}
我在从 listView 中选择日期时打开日历弹出窗口 helpItem1
,一切正常!我想做的是每次选择不同的列表项时将 calendar.selectedDate
设置为 listView
项的日期。
我用来创建 listView
的数组 (userModel
) 的摘录是:
{"date":1551960000000, "name": user1},{"date":1552046400000, "name": user1},{"date":1552219200000, "name": user1}
我的代码的最小部分是:
ListPage {
id: userPage
model: userModel
delegate: SimpleRow {
id: userRow
width: userPage.width
text: modelData.name
detailText: new Date(modelData.date).getTime()
onSelected: {
helpItem1.visible = true
calendar.selectedDate = new Date(modelData.date).getTime()
}
}
Item {
id: helpItem1
visible: false
Rectangle {
id: calendarPage
anchors.centerIn: parent
width: parent.width
height: parent.height
AppButton {
id: backButton
onClicked: {
helpItem1.visible = false
}
//Button used to close the `helpItem1` pop-up
}
Flow {
id: row
Calendar {
id: calendar
focus: true
selectedDate: new Date()
}
// Rest of calendar Code
}
}
}
}
我的问题是:
我如何获取每个 SimpleRow
项目的选定日期,并在弹出窗口打开时将其设置为 calendar.selectedDate
?
我尝试了
的几种变体SimpleRow.onSelected: {calendar.selectedDate = new Date(modelData.date).getTime()}
但没有任何帮助。
在调整后的 9 分钟内,我想通了:
从我的 onSelected {...}
部分中删除 .getTime()
一切正常!
onSelected: {
helpItem1.visible = true
calendar.selectedDate = new Date(modelData.date)
}