cancel
Showing results for 
Search instead for 
Did you mean: 

Path in Aggregation binding

jitendra_it
Active Contributor
0 Kudos

Hello,

I am trying to understand aggregation binding from Walkthrough. In Step 21(Data types), I see that models are accessed in two ways, one using '/' and one without '/' in file "InvoiceList.view.xml". Could you please let me know the difference between them?

Accepted Solutions (0)

Answers (5)

Answers (5)

ericci
Active Contributor

Hi Jitendra Soni,

the "/" means "access the root of the path". So when you do invoice>/Invoces it means, access the "invoice" ODataModel (or JSONModel) and take all the items from the path "/Invoces".

Inside the List aggregation (in this case items) you have a relative path to the looped element, that's why you don't need (and you don't have to use it) the "/" char.

So each item is already bound to a record of the "/Invoces" array and each time it's automatically appending the correct path like "invoice>/Invoices/0/Quantity", "invoice>/Invoices/1/Quantity", "invoice>/Invoices/2/Quantity" and so on.

saurabh_vakil
Active Contributor

For {path:'invoice>ExtendedPrice'} the root of the binding path invoice>/Invoices which is the aggregation holding all the invoice records is already set in the ObjectListItem's items aggregation and therefore the ExtendedPrice property can be accessed using the relative binding path (relative to /Invoices) without the leading '/'.

However, for {path:'view>/currency'} where the property currency exists directly in the view model, you have to use absolute binding path to access the property currency with a leading '/' (view>/currency).

As a rule of thumb:

Absolute binding paths always start with a leading '/' (for e.g. /Invoices, model>/Products etc.)

Relative binding paths never have a leading '/'.

In the image you can see two paths absolute and relative path.

A binding path can either be absolute or relative: Absolute binding paths start with a slash, relative binding paths start with a name token and are resolved relative to the context of the control that is bound.

You can refer this link.

2019-01-17-14h08-54.png

jitendra_it
Active Contributor
0 Kudos

Thanks saurabh for your help.

I tried by changing the json for currency(which is there in controller Init method) and made it exact same as invoice list.

still , not able to access currency using relative path. I made same thing like below

new JSONModel( { "curr": [ { "currency : "EUR" } ] }).
jitendra_it
Active Contributor
0 Kudos

Thanks guys for your help.

From your answers I can understand that first we have to set the model then we can access its properties.

but, if you see in below code, path for currency is set using /

parts: [{path: 'invoice>ExtendedPrice'}, {path: 'view>/currency'}], 

and when accessing it(below code) , again '/ 'is used. I tried without '/' but didn't worked. So my query is once is path is set using '/' then why again it is accessed using '/'.

numberUnit="{view>/currency}"