on 01-17-2019 8:15 AM
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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 '/'.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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" } ] }).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.