cancel
Showing results for 
Search instead for 
Did you mean: 

Binding problem/conflicts with equal names in JSONModel

dominik_auras
Participant
0 Kudos

Hi,

i got a JSONModel (named as "MyModel") with data like this:


{

     "id": 1,

     "title": "Entry title",

     "subData": [

          {

               "id": 123,

               "title": "Title of my first sub data"

          },

          {

               "id": 456,

               "title": "Title of my second sub data"

          }

     ]

}

I set the model to my component and now I want to display the data of my model in my XML view including the data under "subData" like this:


...

<ObjectAttribute text="{MyModel/title}" title="Title"/>

...

<VBox xmlns="sap.m" items="{MyModel>/subData}">

     <Button text="{MyModel>title}"></Button>

</VBox>

...

For the button data binding I use {MyModel>title} as of I read this in an article I found and no other combination I tried worked.

But as you would expect it always displays "Entry title" as of the same attribute exists already in my model.

If I rename the title attribute of "subData" like for example "subTitle" the correct content is displayed.

But I think this can't be the solution ....

So any idea / advice how to set the binding correctly?

Thank you and kind regards,

Dominik

Accepted Solutions (1)

Accepted Solutions (1)

former_member183518
Active Participant
0 Kudos

You're binding path is correct and there is no way for a conflict. You should be getting button text as "Entry Title" only if the binding path is "{MyModel>/title}" (Absolute path). I guess you're xml view could have been cached when you were trying diff combinations. Just confirm with the source of the xml view from the Network response. 

dominik_auras
Participant
0 Kudos

Yeah, thanks! 😃

That really was the problem! Now I'm on an other computer and suddenly it works!

I've tried a lot combinations and caching can definitely be the reason.

But in general:

Am I right that "MyModel>title" is just temporary at this moment (during loop)?

Is this and all possibilities (static behaviour, behaviour in loops, etc.) of binding conventions clearly documented somewhere?

That would be great.

But this topic is now solved for me!

Thanks for the help!

Dominik

former_member183518
Active Participant
0 Kudos
Am I right that "MyModel>title" is just temporary at this moment (during loop)?

I'm not sure what you mean by temporary.  When the aggregation binding happens, the binding path of the buttons will be resolved to,

1st btn -  MyModel>/subData/0/title  

2nd btn- MyModel>/subData/1/title


You can make use of the UI5 diagnostics tools (ctlr + Alt+ Shift + s) to view the controls binding paths info during the runtime.


http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/708342c9-7705-3310-649e-ffcc55b77...

dominik_auras
Participant
0 Kudos

I thought about "MyModel>title" is like a "temporary" variable in which the loop sets the data of "MyModel>/subData/0/title" and "MyModel>/subData/1/title".

But that's not correct. Maybe that's the thinking when coming from ABAP

But after reading a bit more (thanks for the document!!) and thinking about it, it makes more sense if you ignore the (a bit confusing) "MyModel>" for a moment. Then its clear that the binding loops over the "/subData" array and sets the current element as binding. And then what's left are the attributes of the current object like "title" (without the "/") because "/" is for absolute binding.

Following lines of the document made this clear:

So now it's clear for me!

Thank you and kind regards,

Dominik

Answers (1)

Answers (1)

saivellanki
Active Contributor
0 Kudos

Hi Dominik,

Not sure, whether this is what you are expecting? JS Bin - Collaborative JavaScript Debugging

Regards,

Sai Vellanki.

dominik_auras
Participant
0 Kudos

Hi Sai,

yes, this is exactly what I want to accomplish.

But I can't notice any difference from my setup ... 😕

In my scenario the buttons have the same title like the object Attribute.

Where is the key?

Regards,

Dominik

former_member182372
Active Contributor
0 Kudos

i guess that is exactly what he is doing but getting different result

former_member182372
Active Contributor
0 Kudos

do you use core as model scope or component/view? do you do bindElement to the view?

dominik_auras
Participant
0 Kudos

setModel in Component.js and no bindElement in view.