Skip to Content
author's profile photo Former Member
Former Member

Binding problem/conflicts with equal names in JSONModel

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Oct 20, 2015 at 05:59 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Sakthivel Elango

      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

      Unbenannt.jpg (133.7 kB)
  • Posted on Oct 20, 2015 at 04:44 PM

    Hi Dominik,

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

    Regards,

    Sai Vellanki.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.