0

I have two array :

one containing my data : the array name is arrayData

one containing the index of my data arrayIndex

In my xml view I loop over my arrayIndex and I want to display the row corresponding in arrayData.

Is it possible? if yes how too?

Thanks and regards.

2 Answers 2

1

Here's a slick way to do it: send the job to your Formatter.js function.

  1. I'll bind an aggregation, and let's say I expand to some AddressSet:

    <Table id="someTable" 
        items="{path: '/MainSet',
        parameters : 
            {expand:'AddressSet'}
        }"
        growing="true" growingScrollToLoad="true"
     >
    
  2. Then create a control within the aggregation where I send an expanded entityset to my formatter

    <Text 
       text="{
          parts:[
            {path: 'AddressSet'},
          ],
          formatter: '.formatter.addressInSearchCatalog'
        }"
    

    >

  3. Then, in the Formatter, you'll notice that the expanded entityset simply returns you a string that is the relative path of the object. Using this path, I can access the property from my oData model! Obviously, in Javascript I can simply grab the first (or second, or fifth, or last) array item from the array I pass into the formatter function.

     addressInSearchCatalog: function(otherSet){
                var oModel = this._oCatalog.getModel();
                var addressObj = oModel.getObject("/" + otherSet[0]);//use absolute binding
                    return(addressObj.HouseNumber + space + addressObj.Street + space + addressObj.City + ", " + addressObj.State + space + addressObj.Zip);
                }
            }
        }
    
Sign up to request clarification or add additional context in comments.

Comments

0

You need to merge arrayData into your arrayIndex first, so your structure may look like this:

{ arrayIndex: [
    { text: 'test1', arrayData: { otherText: 'testData2' } },
    { text: 'test2', arrayData: { otherText: 'testData2' } }
]}

Now you may use a Table within a Table (sap.m Namespace). Be sure, to define your models and modelnames before.

<Table items="{arrayIndex>/}">
    <columns>
        <Column>
            <Text text="Headline"/>
        </Column>   
    </colums>           
        <items>
            <ColumnListItem>
                <cells>
                    <Text text="{arrayIndex>text}"/>
                        <Table items="{path: 'arrayIndex>arrayData', templateShareable:false}">
                            <columns class="backgroundBlue">
                                <Column>
                                    <Text text="Headline arrayData"/>
                                </Column>
                            </columns>
                                <items>
                                    <ColumnListItem>
                                        <cells>
                                            <Text text="{arrayIndex>otherText}"/>
                                        </cells>
                                    </ColumnListItem>
                                </items>
                        </Table>
                </cells>
            </ColumnListItem>
        </items>
</Table>

You must use {path: '...', templateShareable:false} for your second table in order to work properly.

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.