feat(StatusQ): introduce JSONListModel

This commit is contained in:
Patryk Osmaczko 2022-10-15 19:48:21 +02:00 committed by osmaczko
parent de4ef7daf0
commit 3aae2603f4
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,48 @@
import QtQuick 2.14
import QtQml.Models 2.14
/**
Converts JSON string array to ListModel
JSONListModel {
id: jsonModel
json: JSON.stringify([
{
"name": "Activism",
"emoji": "✊",
},
{
"name": "Career",
"emoji": "💼",
},
])
}
TagsRow {
model: jsonModel.model
}
*/
Item {
id: root
property string json
readonly property ListModel model: ListModel { id: jsonModel }
onJsonChanged: {
jsonModel.clear()
if (json === "") return
try {
const arr = JSON.parse(json)
for (const i in arr) {
jsonModel.append(arr[i])
}
}
catch (e) {
console.warn(e)
}
}
}

View File

@ -4,3 +4,4 @@ EmojiJSON 1.0 emojiList.js
XSS 1.0 xss.js
singleton Utils 0.1 Utils.qml
singleton Emoji 0.1 Emoji.qml
JSONListModel 0.1 JSONListModel.qml