HELP! How do I stop duplicate entries appearing in my ListView?

0
Hi I’m brand new to Mendix and also a student currently studying Web and mobile development (1st year). Part of my university assignment is to create a Weather app using Mendix to display current weather information using the: “Openweathermaps.org” API. So far, I’ve successfully connected my app to the API and displayed the results in a Listview. The problem is, I have got 2 JSON Objects: “JsonObject” and “JsonObject_2”. The first object contains important weather data such as: City Name, Temperature, Humidity, Pressure, Wind Speed, etc. The second object simply contains a string (description) of the current weather forecast (e.g. Clear skies). The problem is, however, only the first JSON object is accessible inside my weather page – the second object doesn’t appear inside the “Select Attribute” context menu for some unknown reason? Personally I think this could be something to do with my Microflow? –  Perhaps it could be programmed to check each object individually to stop duplicate entries from showing in my Listview? I have read through the Mendix documentation, completed relevant courses in the online Academy and searched the internet desperately looking for an answer.  I’m obsessed with trying to find solutions to technical problems and I’ve spent many days and nights – missing out on several hours of sleep just trying to find a solution to this problem and I’m still nowhere near to solving it.  For all you Mendix experts out there, please help!  Kind Regards, Gareth Davies
asked
2 answers
2

The problem is the association. Your JsonObject can have multiple JsonObject_2 objects associated. Even if it is only 1, it could be a list.

You have multiple options to display the data.

  1. You could have a nested ListView inside of your first one. This listview should now be able to show the JsonObject_2 data.
  2. You could parse your data after the API call and store everything in a single entity
  3. Your JsonObject entity could have a calculated attribute that retrieves the JsonObject_2 information (description) via a microflow. in this microflow you can add the logic you need to decide which one to show. I don’t recommend this if you want to show a large amount of weather information (As the calculation microflow will run for each object)
  4. Add a description attribute to your JsonObject and add a change action after your API call to copy the description over from the JsonObject_2 object.

I hope this is giving you an idea on how to deal with it. If not, feel free to ask.

answered
0

Since the association between “JsonObject” and “JsonObject_2” is 1 – many, you need to add a list view inside the original list view (data source should be association or microflow since it’s a non-persistable entity). This is because you must represent a list of objects with a List view/Data grid/Template grid. Moreover, if you know that there will always be only 1 “JsonObject_2” object to each “JsonObject”, you can use a data view with a retrieve by microflow data source and get the first “JsonObject_2” object in the  “JsonObject_2” list by using Head list operation.

answered