0

I am trying to bind a nested array to a list in a table.

{
    "activities": [{
            "activityId": "1",
            "activityName": "tennis",
            "activityHours": [{
                "hour": "09:00",
                "instructor": "dave"
            }, {
                "hour": "10:00",
                "instructor": "Emma"
            }]
        }, {
            "activityId": "2",
            "activityName": "swimming",
            "activityHours": [{
                "hour": "09:00",
                "instructor": "Ella"
            }, {
                "hour": "10:00",
                "instructor": "Ron"
            }]
        }

    ]

}

my view.xml code:

<Table id="tblFactories" items="{path: 'data>/activities'}">
    <items>
<ColumnListItem >
<cells>
<Text text="{data>activityName}"></Text>
<List  items="{path: 'data>/activityHours'}" >
<StandardListItem  title="{data>hour}" ></StandardListItem>
</List>
    </cells>
</ColumnListItem>
</items>
</Table>

but it is not working. does anyone know what is the correct syntax for the List binding?

Thanks!

1 Answer 1

1

In your XML code, the path is incorrect. For the List, activityHours is a property of the parent object so you should remove the '/'. For the List the context will be as below.

enter image description here

<Table id="tblFactories" items="{data>/activities}">
    <columns>
        <Column>
            <Text text="Activity Name" />
        </Column>
        <Column>
            <Text text="Hours" />
        </Column>
     </columns>   
        <items>
            <ColumnListItem >
            <cells>
                    <Text text="{data>activityName}"></Text>                        
                    <List  items="{data>activityHours}" >
                    <StandardListItem  title="{data>hour}" ></StandardListItem>
                    </List>                        
            </cells>
            </ColumnListItem>
        </items>
    </Table>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.