How to make use of navigation property?

前端 未结 1 1807
北荒
北荒 2021-01-13 19:14

An OData service (V2) contains multiple navigation properties as following:

ClassNum: \"ZPM_TEST_01\"
ClassNumDescr: \"ZPM_TEST_01\"
ClassType:          


        
相关标签:
1条回答
  • 2021-01-13 20:03

    Navigation properties are, as the name suggests, properties with which you can navigate to related entity types (spec). The UI5 framework supports this feature too so that app developers don't have to extract URLs by hand. In fact, you won't even need to call read. Let's take this EDM[1] for example:

    Customer
    Nav: "Orders"
    1 ___ n Order
    Nav: "Customer"

    ... from this Northwind service (metadata)

    Navigating from one entity to a collection:

    <Page binding="{/Customers('ALFKI')}">
      <List items="{Orders}">
        <StandardListItem title="{OrderID}" />
      </List>
    </Page>
    

    Navigating from one entity to another single entity:

    <Page binding="{/Orders(10643)}">
      <Panel binding="{Customer}" headerText="{ContactName}" />
    </Page>
    

    Here is an example using navigation properties: https://embed.plnkr.co/F3t6gI8TPUZwCOnA

    In your case, you'd use either to_IClassHeaderVh or to_IClassVh in place of Customer or Orders. UI5 will then send requests for you accordingly. Keep in mind that only context- and aggregation-bindings handle sending requests. Property-binding does not.

    In case you're wondering about the binding attribute in XML; it's just one of the ways to bind a single entity (context). If you need to specify entity keys (IDs) dynamically, which is usually the case, you'll have to use the API bindElement[API] in JS instead. I'm hardcoding the keys here just for the sake of the examples.

    Additionally, you can also add the binding parameter expand which awaits navigation property name(s).

    <Page binding="{
      path: '/Orders(10643)',
      parameters: {
        expand: 'Customer'
      }
    }" >
      <!-- ... -->
    </Page>
    

    Response: https://services.odata.org/V2/Northwind/Northwind.svc/Orders(10643)?$expand=Customer&$format=json

    Here is an example making use of expand: https://embed.plnkr.co/wAlrHB


    [1]: "Entity Data Model" - OData specific E/R model

    0 讨论(0)
提交回复
热议问题