cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

UI5 data binding question

trmt
Explorer
0 Likes
944

Hello ��

I started learning UI5 and I'm having a bit of trouble with data binding.

Let's say I have a list of directors:

directors.json
[
   {
      "directorID":1,
      "name":"Christopher Nolan",
      "age":52,
      "location":"London",
      "oscars":5
   },
   {
      "directorID":2,
      "name":"Quentin Tarantino",
      "age":59,
      "location":"United States",
      "oscars":8
   }
]

That I will display in a list.

On clicking a certain director I would like to take the user to another page, basically another list that will show the movies of this director. These movies will be taken from another .json file that has a few entries with the directorID as the common key between the two:

<strong>movies.json</strong>
<strong>[
   {
      "directorID":1,
      "movieID":1,
      "name":"Inception",
      "year":2010,
      "mainCharacter":"Leonardo Di Caprio"
   },
   {
      "directorID":1,
      "movieID":2,
      "name":"Interstellar",
      "year":2014,
      "mainCharacter":"Matthew McConaughey"
   },
   {
      "directorID":1,
      "movieID":3,
      "name":"Tenet",
      "year":2020,
      "mainCharacter":"John David Washington"
   },
   {
      "directorID":2,
      "movieID":4,
      "name":"Pulp Fiction",
      "year":1994,
      "mainCharacter":"John Travolta"
   },
   {
      "directorID":2,
      "movieID":5,
      "name":"Inglourious Basterds",
      "year":2009,
      "mainCharacter":"Brad Pitt"
   },
   {
      "directorID":2,
      "movieID":6,
      "name":"Django",
      "year":2012,
      "mainCharacter":"Jamie Foxx"
   }
]</strong><br>

What would be the best to way to filter the results on the second list based on the argument passed in the route: .../directors/{directorID}?

As of now, I could send from navTo and capture the directorID in _onRouteMatched via the getParameter method, but after this I'm a bit stuck.

I also searched for a sample to see this technique in action but I couldn't find any, some recommendation on this would also be appreciated.

Thanks

edit: The code that I'm asking about is found here: https://plnkr.co/edit/0WI2yiG56Nzspk0l

View Entire Topic
Tukutupap
Participant
0 Likes

I think you got it, it just would be /movies/{directorID} since you want to display the movies for a particular director.

trmt
Explorer
0 Likes

That is not the problem I have.

The thing is I don't know how to query the right data to show in the Movies view once the director was pressed in the list.

This is the code: https://plnkr.co/edit/0WI2yiG56Nzspk0l

Can you please give me a hint where in the Movies.controller.js & how this filtering of movies based on director's id should be done?

Thanks

Tukutupap
Participant

I'm sorry, but for some reason I cant reach that page. Must have something to do with my company's policy maybe. I tried to take a peak on my phone but it was pretty bad.

Anyways, I don't think you need to do anything in your controller, your OData model takes care. You just need to build the corresponding association/navigation between your movies and your directors. You do that in your OData service in your backend, the rest happens automagically.

So again, no code. Just make sure your next panel has the right binding according to the navigation you have built. So an example would be "/directors/{directorId}/movies".

Check this out.

Kr,