JSON data in repeater

Hi!
I’m trying to get the temperature of each hour from this website: https://www.smhi.se/vader/prognoser/ortsprognoser/q/Stockholm/2673730
I have found the api and I have retrieved the data that I want. This is my backend-code (which works):

import { getJSON } from 'wix-fetch';

export async function getWeather() {

    try {
        const response = await getJSON('https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/16/lat/58/data.json');

        console.log(response)  // all data

        const tempData = response.timeSeries[0].parameters[10].values[0];

        return tempData // Only returns "t" - temperature

    } catch (e) {
        return e;
    }

}

However, I’m having problems with putting that data into a repeater. I think the problem is that the “id” that you would normally have is an object in this case. Another problem is that the object for the temperature,“t”, has different objects too. (It will become clear if you look at the data). This is my frontend-code:

import { getWeather } from 'backend/getSMHI.jsw'

$w.onReady(function () {
    (

        getWeather().then(weatherInfo => {

            $w('#weatherRepeater').onItemReady(($item, itemData, index) => {

                if (index > 6) {
                    $item('#tempText').text = itemData.timeSeries[index].parameters[1].values[0];   
                    
                } else if (index === 6) {
                    $item('#tempText').text = itemData.timeSeries[index].parameters[0].values[0];

                } else {
                    $item('#tempText').text = itemData.timeSeries[index].parameters[10].values[0];
                } // The parameters number for "t" changes depending on the index
            })
            $w('#weatherRepeater').data = weatherInfo;
        })
    )
})

Please post the weatherInfo data, so I’ll be able to take a look at its structure.

You are correct. You’ll need to add a “_id” value within your getweather data at the backend for it to load within the repeater.

The _id value will need to be unique. You can probably use a combination of date/time with a random generated number.

something like this.



try{
const response =awaitgetJSON('https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/16/lat/58/data.json');          
console.log(response)// all data

const newData = [];

for (let i = 0; i < response.length; i++) 
{    
const now = new Date();
const _id = `weatherdata-${now.getTime()}_${Math.floor(Math.random() * 10000)}`;
const tempData = response.timeSeries[0].parameters[10].values[0]; // Only returns "t" - temperature};
newData.push({ _id, tempData}); 
}

return newData
}