0

I try to update nested list data of list elements within a list model:

Item {

  width: 400
  height: 300

  ListModel {
    id: myModel
    ListElement {
       name: "Banana"
       myId: "1.95"
       attributes: [
          ListElement { event: "Tropical" }
       ]
     }

  }

  MouseArea {
     anchors.fill: parent
     onClicked: {
        myModel.setProperty(0, "attributes", {"event" : "testNEW"}); 
        //myModel.setProperty(0, "attributes", [{"event" : "testNEW"}]); 
     }
  }

  ListView {
     anchors.fill: parent

     model: myModel
     delegate: Item {
        height: 50
        width: 100
        Repeater {
            model: attributes
            Text { text: event }
        }
     }
  }

  Component.onCompleted: {
    myModel.append{"name" : "name", "myId" : "2.23", "attributes" : [{"event" : "test"}];    
  }    
}

The problem is that the code above did not update the attributes property.

The only way how to update the property was using following code:

myModel.get(0).attributes.get(0).event = "testNEW"

Question

How to update the attributes property with setProperty?

2
  • Hmm ... did you test your code before posting here? What does id: 1.95 mean? The line with myModel.append contains at least 3 errors. Please correct it.
    – folibis
    May 26, 2016 at 15:39
  • Ohh...sry. Mixed up some stuff when writing the code directly here. Should be fixed now.
    – sk2212
    May 26, 2016 at 15:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.