Hey Guys!
I’m currently trying to adjust a value of some data in my JsonModel from true/false, the information isn’t downloaded from a webserver or anything, it’s hardcoded into my application, what i’m trying to do is create a drop-down list using, the JsonListModel;
I have tried working with the jsonModel.set() or jsonModel.setPropertys() – neither error, and both log the corrent change, but dont update the entry, i’m not looking at adding a new property – simply changing a Boolean within; working with a previous ‘dropdown’ list tutorial I have so far:
What I am looking to do, is change the ‘jsonData’ property from true/false when I send the signal (when I console.log my current signal, It is ‘flicking the switch’ so to speak, but not updating my JSON – how could I go about this?
I further want the ‘height’ property to naturally be adjusted dependant on the ‘content’ of the row, is there a way I can access ‘contentHeight’ of my simpleRow delegate?
Code below!
Thanks!
Page {
id: faqPage
property bool expanded: false
property var currIndex
JsonListModel {
id: jsonModel
source: faqPage.jsonData
keyField: "id"
fields: ["id", "title", "content", "avisible"]
}
SortFilterProxyModel {
id: sortedModel
Component.onCompleted: sourceModel = jsonModel
sorters: StringSorter { id: typeSorter; roleName: "title"; ascendingOrder: true }
}
AppListView {
id: listView
anchors.fill: parent
property string expandedSection: ""
model: sortedModel
delegate: SimpleRow {
id: rowDelegate
visible: model.avisible
onVisibleChanged: {
if(visible){
(listView.currentIndex = currIndex) === currIndex
height = dp(350)
}else
height = 0
}
}
section.property: "title"
section.delegate: SimpleSection {
id: sectionHeadRect
property bool isExpanded: false
property string currentExpandedSection: ListView.view.expandedSection
onCurrentExpandedSectionChanged: {
if(currentExpandedSection === section) {
isExpanded = true
} else {
isExpanded = false
}
}
onIsExpandedChanged: {
if(isExpanded){
expanded = true
ListView.view.expandedSection = section;
} else
expanded = false
for(var i=0; i<jsonModel.count; i++){
var animal = jsonModel.get(i);
if(title === animal.title)
animal.aVisible = sectionHeadRect.isExpanded;
}
}
onSelected: {
currIndex = jsonModel.indexOf("title", title)
sectionHeadRect.isExpanded = ! sectionHeadRect.isExpanded;
}
enabled: true
}
}
property var jsonData: [
{
"id": 1,
"title": "title 1",
"content": "cont1",
"avisible": false
},
{
"id": 2,
"title": "title2",
"content": "cont2",
"avisible": false
},
{
"id": 3,
"title": "title3",
"content": "cont3",
"avisible": false
}
]
}