Paul Rintisch
Paul Rintisch

Reputation: 11

Binding multiple JSON Models into one View

I´m working on a table to display different Entitys in SAP UI5. My Mockserver has stored 2 different JSON Files: Consumers.json & Orders.json. How can I implement them both into one table? My current code:

The view with the table:

<Table 
    id="belege" 
    class="sapUiResponsiveMargin" 
    width="auto"
    growing ="true"
    growingThreshold="15"
    growingScrollToLoad="false"
    items = "{path : 'tcdata>/Orders', parameter: {expand : 'Customers'}}">
    <headerToolbar>
        <Toolbar>
            <Title text="{i18n>showTitleText}"/>
        </Toolbar>
    </headerToolbar>
    <columns>
        <Column>
            <Text text="{i18n>columnName1}"/>
        </Column>
        <Column>
            <Text text="{i18n>columnName2}"/>
        </Column>
        <Column>
            <Text text="{i18n>columnName3}"/>
        </Column>
        <Column>
            <Text text="{i18n>columnName4}"/>
        </Column>
        <Column>
            <Text text="{i18n>columnName5}"/>
        </Column>
        <Column>
            <Text text="{i18n>columnName6}"/>
        </Column>
    </columns>
    <items>
        <ColumnListItem type="Navigation" press="onPress">
            <cells>
                <ObjectIdentifier 
                title ="{tcdata>/Customers/ContactName}"
                text="{tcdata>Customers/CompanyName}"/>
                <ObjectIdentifier 
                text ="{Customers/Country}"/>
                <ObjectNumber
                number ="{tcdata>PostalCode}"/>
                <ObjectIdentifier  
                text="{tcdata>ShipCity}"/>
            </cells>
        </ColumnListItem>
    </items>
</Table>
</mvc:View>

Customers.json:

[{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"Address": "Obere Str. 57",
"City": "Berlin",
"PostalCode": "12209",
"Country": "Germany",
"Phone": "030-0074321",
"Fax": "030-0076545"}]

Orders.json:

[{
"OrderID": "10248",
"Customer": "VINET",
"EmployeeID": "5",
"OrderDate": "1996-07-04T00:00:00",
"RequiredDate": "1996-08-01T00:00:00",
"ShippedDate": "1996-07-16T00:00:00",
"ShipVia": "3",
"Freight": "32.3800",
"ShipName": "Vins et alcools Chevalier",
"ShipAddress": "59 rue de l'Abbaye",
"ShipCity": "Reims",
"ShipPostalCode": "51100",
"ShipCountry": "France"}]

Upvotes: 0

Views: 627

Answers (1)

RelativePeezyness
RelativePeezyness

Reputation: 76

Note that the items declaration is trying to find objects from a model called tcdata and the link /Orders that now has the following parameters $expand=Customers.

i.e

<tcdata-Uri>/Orders$expand=Customers

For this to work, there would need to be some relationship between the root path and Customers. Like if you had this as your Orders json:

[{
    "Id": 12,
    "Name": "Order1",
    "Customers": {
        "Name": "Customer1",
        "ContactName": "Person1"
    }
}]

Then the Orders Item would be expanded to include the Customers details.

Upvotes: 1

Related Questions