Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
How to display the new list from local storage?

How do I display the new list from local storage? When the user inputs a new search, that displays fine, and get's added to the localstorage. However it doesn't show the updated list in the last requests on the website. Currently it only shows it when refreshing the website. So basically how do I re-run / re-display the new and updated list from localstorage? Can post the HTML if neccesary

// Local Storage
function SaveDataToLocalStorage(data) {
  var a = [];
  // Parse the serialized data back into an aray of objects
  a = JSON.parse(localStorage.getItem('last-requests')) || [];
  // Push the new data (whether it be an object or anything else) onto the beggining of the array
  a.unshift(data)
  // If more than 5 requests remove (pop) last request
  if (a.length > 5) {
    a.pop()
  }
  // Re-serialize the array back into a string and store it in localStorage
  localStorage.setItem('last-requests', JSON.stringify(a));
displayLastRequests()
};
// Displays last 5 requests/searches
function displayLastRequests() {
  const lastReq = JSON.parse(localStorage.getItem('last-requests'))
  console.log(lastReq)
  // for loop request
  for (req of lastReq) {
    var clone = $($("#last-request-template").html());
    clone.appendTo(".last-requests");
    clone.find(".cityname").text(req.city_name);
    clone.find(".cityweather").text(req.weather);
    clone.find(".imgs").attr('src', req.imgurl);
    clone.find(".citytemp").text(req.city_temp + " °C");
    clone.find(".citywind").text(req.city_wind + " m/s");
  }
};

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda