FlowersLeaves
FlowersLeaves

Reputation: 171

How to access nested Repeaters

I want to fill the colours in the following rectangles created through Repeaters, dynamically.

I am not able to access the bottom Repeater at all.

How should I access "all" the rectangles here?

Row
{
    spacing: 20
    Repeater
    {
        id: repeater3

        property Repeater repeater2: repeater2

        model: head.rows
        Column
        {
            id: columnInBetween
            spacing: 20
            Repeater
            {
                id: repeater2
                model: head.columns
                property Row row1: row1
                Row
                {
                    id: row1
                    property Repeater repeater1: repeater1
                    Repeater
                    {
                        id: repeater1
                        model: 2
                        Rectangle
                        {
                            width: 20; height: 20
                            color: "red" 
                        }
                    }
                }
            }
        }
    }
}

Upvotes: 2

Views: 2271

Answers (1)

Crawl.W
Crawl.W

Reputation: 421

Repeater will expand Item they contain. So you can use .children[index] to access those Items expanded.

In your case:

/*0< index < head.rows
you get first Column expanded by repeater3*/
repeater3.itemAt(index).children[0]

/*0< index < head.columns
you get first Row of first Column expanded by repeater3 and repeater2*/
repeater3.itemAt(index).children[0].children[0]

/*0< index < 2
you get first Rectangle of first Row of first Column expanded by repeater3 and repeater2 and repeater1*/
repeater3.itemAt(index).children[0].children[0].children[0]

Reminder: you are getting a head.columns rows and 2 * head.rows columns of tables.

Upvotes: -1

Related Questions