0
votes

I am using a nested JSON file as mockup data in a ODATA SAPUI5 application, but I cannot access the nested data.

JSON content

[{
"testcase": {       
    "specification": "SRS PR 28717 – Deposit in Brazilian Reais",
    "execution": {
        "description": "DESC",
        "bca_cn_acct_01": {
            "header": {
                "section": "Field / Section Name",
                "data": "Data to Enter / Value to Select",
                "action": "Activity / Check / Comment"
            },
            "frame": {
                "ID": 1,
                "title": "Create Account: Initial Screen",
                "data": [{
                    "key": "Contract Start",
                    "value": "02/16/2000",
                    "action": ""
                }, {
                    "key": "Contract Manager",
                    "value": "GH_RAMOSCL",
                    "action": ""
                }, {
                    "key": "Product",
                    "value": "BR_IOFTC3",
                    "action": ""
                }, {
                    "key": "Account Holder",
                    "value": "GH_IOF_COR",
                    "action": "Press Enter"
                }]
            }

        }
    },
    "result": "Teste"
}}]

In my view file, I want to access the data inside the tag, as a list:

<core:View controllerName="sap.ui.demo.MockServer.controller.App" xmlns:core="sap.ui.core" xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="sap.m">
<!-- <List headerText="{i18n>headerText}" id="list" items="{/Meetups}" noDataText="{i18n>noDataText}">
    <items>
        <ObjectListItem number="{ path: 'EventDate', type: 'sap.ui.model.type.DateTime', formatOptions: { style: 'medium' } }" title="{Title}">
            <attributes>
                <ObjectAttribute text="{Description}"/>
            </attributes>
        </ObjectListItem>
    </items>
</List>
<Button press="onPressAction" text="{i18n>loadFirstItems}"></Button> -->
<List headerText="{i18n>headerText}" id="list" items="{/Meetups}" noDataText="{i18n>noDataText}">
    <items>
        <ObjectListItem number="{ path: 'EventDate', type: 'sap.ui.model.type.DateTime', formatOptions: { style: 'medium' } }"
            title="{testcase/execution/description}">
            <attributes>
                <ObjectAttribute text="{specification}"/>
            </attributes>
        </ObjectListItem>
    </items>
</List>
<Table id="table" items="{/Meetups}">
    <columns>
        <Column width="12em">
            <Text text="Field / Section Name"/>
        </Column>
        <Column minScreenWidth="Tablet" demandPopin="true">
            <Text text="Data to Enter / Value to Select"/>
        </Column>
        <Column minScreenWidth="Tablet" demandPopin="true">
            <Text text="Activity / Check / Comment"/>
        </Column>
    </columns>
    <items>
        <ColumnListItem>
            <cells>
                <ObjectIdentifier title="{testcase/execution/bca_cn_acct_01/frame/data/key}" class="sapMTableContentMargin"/>
                <!-- <Text text="{testcase/execution/bca_cn_acct_01/bca_dte_event_begin_d}" /> -->
                <Text text="{testcase/execution/bca_cn_acct_01/frame/data/value}"/>
            </cells>
        </ColumnListItem>
    </items>
</Table>
<Button press="onPressAction" text="{i18n>loadFirstItems}"></Button>

However, data from fields key and value are not retrieved as list, although they are an array inside the JSON data tag.

I use as base the sample tutorial from SAPUI5 library: https://sapui5.hana.ondemand.com/#docs/guide/7a78f1b707c248fd9ec53dcb5f10814c.html

And below you can find the metadata file I have been using:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<edmx:Edmx Version="1.0"
    xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
    <edmx:DataServices
        xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
        <Schema Namespace="NerdMeetup.Models"
            xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
            xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
            xmlns="http://schemas.microsoft.com/ado/2006/04/edm">            
            <EntityType Name="Meetup">                
                <ComplexType Name="testcase">
                    <ComplexType Name="execution">
                        <!-- Create Payment Item -->
                        <ComplexType Name="bca_cn_acct_01">
                            <ComplexType Name="header">
                                <Property Name="section" Type="Edm.String" Nullable="false" />
                                <Property Name="data" Type="Edm.String" Nullable="false" />
                                <Property Name="action" Type="Edm.String" Nullable="false" />
                            </ComplexType>
                            <ComplexType Name="frame">
                                <Property Name="ID" Type="Edm.Int32" Nullable="false" />
                                <Property Name="title" Type="Edm.String" Nullable="false" />
                                <ComplexType Name="data">
                                    <Property Name="key" Type="Edm.Int32" Nullable="false" />
                                    <Property Name="value" Type="Edm.Int32" Nullable="false" />
                                    <Property Name="action" Type="Edm.Int32" Nullable="true" />
                                </ComplexType>
                            </ComplexType>
                            <Property Name="bca_dte_event_begin_d" Type="Edm.String" Nullable="false" />
                            <Property Name="bca_dte_orgunit_cnmgt" Type="Edm.String" Nullable="false" />
                            <Property Name="fspr_prodext_y" Type="Edm.String" Nullable="false" />
                            <Property Name="bca_dte_bupa_acchold" Type="Edm.String" Nullable="false" />
                        </ComplexType>
                    </ComplexType>
                    <Property Name="specification" Type="Edm.String" Nullable="true" />
                </ComplexType>               
            </EntityType>
            <EntityContainer Name="NerdMeetups" m:IsDefaultEntityContainer="true">
                <EntitySet Name="Meetups" EntityType="NerdMeetup.Models.Meetup" />
                <FunctionImport Name="FindUpcomingMeetups" EntitySet="Meetups" ReturnType="Collection(NerdMeetup.Models.Meetup)" m:HttpMethod="GET" />
            </EntityContainer>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

Any ideas?

Hugs

1
Could you check your sample code - the List appears to have items="{/Meetups}" but there is no node named 'meetups' in your JSON. If this was not an edit error whilst preparing the sample then maybe this is the issue? Similarly path for bjectListItem path: 'EventDate' appears to be wrong. Overall I would say your question is unclear at this stage.Vanquished Wombat
Added some new info in the original post.Claudio Ramos

1 Answers

0
votes

I guess you can either bind the entire array:

{testcase/execution/bca_cn_acct_01/frame/data/}

Or bind an specific element of the array:

{testcase/execution/bca_cn_acct_01/frame/data/0/key}

You could also use a formatter to receive an array and concatenate all the keys of the array check the Formatter SAPUI5 documentation