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

266
Visualizações
Why isn't my localStorage showing the data in the container? It's showing my array in the console and I'm getting no error messages

I'm trying to keep the text entered in a tag and when I refresh it doesn't save and I can't figure out why. I'm not receiving any error in my localstorage, console, or VS.

I have localStorage being called first, and when I go into my console I see the information there.

// fill in and save timeslot items
var myTasks = [];
var nineOclock = document.getElementById("nineoclock");
// call function to get data

var savedTasks = function() {
    localStorage.getItem("myTasks")
    if (savedTasks) {
        savedTasks = JSON.parse(localStorage.getItem("myTasks"))
    } else {
        localStorage.getItem("myTasks", JSON.stringify(myTasks))
    };
};

function retrieveTasks() {
    if (savedTasks.length > 0) {
        savedTasks.forEach(task => {
            console.log("this task is: ", task);
            nineOclock.children[0].children[1].value = task.tasktxtarea
        })
    }
}
    

retrieveTasks();



var addTask = (event) =>{
    event.preventDefault();

    let task = {
        id: Date.now(),
        tasktxtarea: document.getElementById("tasktext").value, 
    }
    
    myTasks.push(task);

    console.log("added", myTasks)
    

    // save to local storage
    localStorage.setItem("myTasks", JSON.stringify(myTasks));
    

    if (moment().isAfter(date)) {
        $(task).addClass("list-group-item-danger");
    } else if (Math.abs(moment().diff(time, "days")) <= 2) {
        $(task).addClass("list-group-item-warning");
    }
         
}
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