Home > other >  Accessing modelData inside nested delegates
Accessing modelData inside nested delegates

Time:06-01

I have a scenario where in I need to access the modelData inside a repeater which part of a listview's delegate. I am unable to differentiate between listview's modelData and Repeater's modelData.

ListView
{
  id: listViewData

  model: listViewData    //here listViewData is QObjectListModel
  delegate: 
      ColumnLayout
      {
        Rectangle
        {
           TextArea
           {
               text: modelData.somePropertyA[index]  // This works fine, no issues
               ....
            }
            Column
            {
                 Repeater
                 {
                   id: repeaterData
                   model: modelData.getCount(modelData.somePropertyB[index])  // here modelData is referencing to listViewData's modelData.
             
                    Text
                    {
                        text: repeaterData.modelData.someFunction(listViewData.modelData)

                        //So my concern here is, how do i differently access listViewData's modelData and repeaterData's modelData. I tried referencing by using id name as you can see. But i am unable to use in this way, it says undefined.
                     }
                  }
             }
        }
     }
}

CodePudding user response:

You can bind the outer model data to some delegate property to create a kind of alias, for example:

Column {
    spacing: 5
    Repeater {
        model: ["A","B","C"]
        delegate: Row {
            spacing: 5
            property var storedValue: modelData
            Repeater {
                model: ["1","2","3"]
                delegate: Text {
                    text: modelData   storedValue
                }
            }
        }
    }
}
  • Related