Warning, /webapps/qmlonline/qml/examples/jsonmodel.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.0
0002 import QtQuick.Controls 2.12
0003 import QtQuick.Layouts 1.0
0004 
0005 Item {
0006     id: root
0007     property var parameters: undefined
0008 
0009     anchors.fill: parent
0010 
0011     ScrollView {
0012         id: scroll
0013 
0014         height: parent.height
0015 
0016         ColumnLayout {
0017             id: parameterButton
0018 
0019             Repeater {
0020                 model: root.parameters ? Object.keys(root.parameters['Sub']) : undefined
0021 
0022                 Button {
0023                     text: modelData
0024 
0025                     Layout.fillWidth: true
0026 
0027                     onClicked: {
0028                         textContent.text = JSON.stringify(root.parameters['Sub'][modelData], null, 2)
0029                     }
0030                 }
0031             }
0032         }
0033     }
0034 
0035     Text {
0036         id: textContent
0037 
0038         anchors.left: scroll.right
0039         Layout.fillHeight: true
0040         Layout.fillWidth: true
0041     }
0042 
0043     function getJson() {
0044         var xmlhttp = new XMLHttpRequest();
0045         var url = "https://jsonblob.com/api/jsonBlob/90eff412-2638-11ea-8b19-194c524ac128";
0046 
0047         xmlhttp.onreadystatechange=function() {
0048             if (xmlhttp.readyState == XMLHttpRequest.DONE && xmlhttp.status == 200) {
0049                 root.parameters = JSON.parse(xmlhttp.responseText)
0050                 progressBar.visible = false
0051             }
0052         }
0053         xmlhttp.open("GET", url, true);
0054         xmlhttp.send();
0055     }
0056 
0057     ProgressBar {
0058         id: progressBar
0059 
0060         width: parent.width
0061         anchors.verticalCenter: parent.verticalCenter
0062 
0063         indeterminate: true
0064 
0065         Label {
0066             text: "loading..."
0067 
0068             font.pixelSize: 30
0069 
0070             anchors.margins: 10
0071             anchors.horizontalCenter: parent.horizontalCenter
0072             anchors.top: parent.bottom
0073             Layout.fillWidth: true
0074         }
0075     }
0076 
0077     Component.onCompleted: getJson()
0078 }