replace this option.text = data[i].styleName;
let keys=Object.keys(data[i])
with option.text = data[i][keys[0]].styleName我的问题是我需要从一个数组(tFields)中读取表中的名称和列数,以及从第二个数组(tRecords)中读取元素数据。
我已经实现了列的读取和创建,请大家帮忙或者告诉我创建列表的问题出在哪里。
这是代码:
function buildColumns() {
var rc = vConnection.recCount
var fc = vConnection.fldCount
for(var i = 0; i < fc; ++i)
{
var str = 'import QtQuick 2.1; import QtQuick.Controls 1.0; import QtQuick.Layouts 1.0; TableViewColumn{ id: idColumn; role: '
str += '"' + vConnection.tFields[i] + '"' + '; title: ' + '"' + vConnection.tFields[i] + '"' + '; width: ' + (tblPage.width / vConnection.fldCount) +'; Component.onCompleted: console.log("YEY");}'
tbl.addColumn(Qt.createQmlObject(str, tbl))
}
for(var j = 0; j < rc; ++j)
{
var str2 = 'import QtQuick 2.12; import QtQuick.Window 2.12; import QtQuick.Controls 2.4; import QtQuick.Controls.Imagine 2.3; import QtQuick.Templates 2.5; import QtQuick.Controls 1.4; ListElement { id: idColumn; '
for(var f = 0; f < fc; ++f)
{
str2 += vConnection.tFields[f] + ': "' + vConnection.tRecords[f + rc] + '"; '
}
str2 += '}'
Qt.createQmlObject(str2, lmTable)
}
}
Component.onCompleted: {
buildColumns();
}
TableView {
id: tbl
anchors.fill: parent
model: ListModel {
id: lmTable
}
}
}
Qyouu
相关分类