QtQuick 2.11
import QtQuick.Window 2.11
Window {
id: root
width: 640
height: 480
visible: true
ListView {
anchors.fill: parent
// model: [
// {"name": "nameA1", "group": 1},
// {"name": "nameA2", "group": 1},
// {"name": "nameA3", "group": 1},
// {"name": "nameB1", "group": 2},
// {"name": "nameC1", "group": 2},
// {"name": "nameC2", "group": 3}
// ]
model: ListModel {
ListElement { name: "nameA1"; group: 1 }
ListElement { name: "nameA2"; group: 1 }
ListElement { name: "nameA3"; group: 1 }
ListElement { name: "nameB1"; group: 2 }
ListElement { name: "nameB2"; group: 2 }
ListElement { name: "nameC1"; group: 3 }
}
delegate: Rectangle {
color: "gray"
width: parent.width
height: 40
// Text { text: modelData.name }
Text { text: name }
}
// section.property: "modelData.group"
section.property: "group"
section.delegate: Rectangle {
color: "green"
width: parent.width
height: 40
Text { text: section }
}
}
}
Component.onCompleted: { for (var k in jsModel) { listModel.append(jsModel[k]) } попробуй так
Обсуждают сегодня