第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何制作動態(tài)表

如何制作動態(tài)表

桃花長相依 2022-05-26 11:12:33
 replace this option.text = data[i].styleName;let keys=Object.keys(data[i])    with option.text = data[i][keys[0]].styleName我的問題是我需要從一個數(shù)組(tFields)中讀取表中的名稱和列數(shù),以及從第二個數(shù)組(tRecords)中讀取元素數(shù)據(jù)。我已經(jīng)實現(xiàn)了列的讀取和創(chuàng)建,請大家?guī)兔蛘吒嬖V我創(chuàng)建列表的問題出在哪里。這是代碼:function buildColumns() {var rc = vConnection.recCountvar fc = vConnection.fldCountfor(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: tblanchors.fill: parentmodel: ListModel {    id: lmTable}}}
查看完整描述

1 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗 獲得超11個贊

不要過度使用字符串連接,因為處理起來可能會令人困惑,相反,您可以使用“組件”的 createObject 方法,該方法可以以更易讀的方式分配屬性。


要將項目添加到模型中,不必使用 X,而是使用 append 方法,您可以在其中傳遞字典,使代碼更具可讀性。


Page {

    id: tblPage

    title: qsTr("Table")


    Component{

        id: columnComponent

        TableViewColumn{

            Component.onCompleted: console.log("YEY")

        }

    }

    ListModel {

        id: lmTable

    }

    function buildColumns() {

        var rc = vConnection.recCount

        var fc = vConnection.fldCount

        for(var i = 0; i < fc; ++i){

            var col = columnComponent.createObject(tbl, {"role": vConnection.tFields[i],

                                                       "title": vConnection.tFields[i],

                                                       "width": (tblPage.width / vConnection.fldCount)})

            tbl.addColumn(col)

        }

        for(var j = 0; j < rc; ++j){

            var d = {};

            for(var f = 0; f < fc; ++f){

                d[vConnection.tFields[f]] = vConnection.tRecords[f + rc]

            }

            lmTable.append(d)

        }

    }

    TableView {

        id: tbl

        anchors.fill: parent

        model: lmTable

    }

    Component.onCompleted: buildColumns()

}


查看完整回答
反對 回復(fù) 2022-05-26
  • 1 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號