使用 QT 5.10.1,我需要用 JS中的SQLite查询在QML中填写我的ComboBox列表。
我的JS的代码是:
function combobox(Prowid)
{
var db = dbGetHandle()
db.transaction(function (tx) {
var results = tx.executeSql(
'SELECT description FROM part_log where rowid = ? order by description asc',[Prowid])
for (var i = 0; i < results.rows.length; i++) {
listModel.append({
id: results.rows.item(i).rowid,
checked: " ",
description:results.rows.item(i).description
})
}
})
}
我需要组合框包含描述列数据。
你能帮我吗?
谢谢!
像这样的东西(对不起,代码格式不好(。此外,您必须从某个地方传递Prowid
参数。
ComboBox {
id: comboBoxContainer
width: 400
height: parent.height
textRole: "text"
model: ListModel {
id: listModel
}
delegate: ItemDelegate {
width: comboBoxContainer.width
height: 50
text: model.text
font.pixelSize: 18
font.weight: comboBoxContainer.currentIndex === model.index ? Font.DemiBold : Font.Normal
}
contentItem: Text {
leftPadding: 0
rightPadding: comboBoxContainer.indicator.width + comboBoxContainer.spacing
text: comboBoxContainer.displayText
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
font.family: "Ubuntu"
font.weight: Font.Normal
font.pixelSize: 18
elide: Text.ElideRight
}
}
Component.onCompleted: {
var db = dbGetHandle()
db.transaction(function (tx) {
var results = tx.executeSql(
'SELECT description FROM part_log where rowid = ? order by description asc',[Prowid])
for (var i = 0; i < results.rows.length; i++) {
listModel.append({
id: results.rows.item(i).rowid,
checked: " ",
text:results.rows.item(i).description
});
}
}
}