【问题标题】:Want to create local storage for created List想要为创建的列表创建本地存储
【发布时间】:2022-06-14 21:04:02
【问题描述】:

当一个新任务被创建时,我希望它使用本地存储来存储,我已经为本地存储做了一个功能。

本地存储正在使用 taskList 数组。当一个新任务被推入数组时,它意味着存储在本地。

JS

//local storage key

const storage_key = "tasks-storage-key";

//variable of empty array that gets new task
 let taskList = [];

/function that creates new tasks with date and time
const creatTask = (task) => {
  const id = createId();
  const taskNew = el.input.value;
  const taskDate = el.date.value;
  const taskTime = el.time.value;

  if (!taskNew) {
    alert("Please add a new Task");
  }
  if (!taskDate) {
    alert("Please add a new Task with a due date");
  }
  if (!taskTime) {
    alert("Please add a new Task with a due time");
  }

      const tasks = document.createElement("div");

      tasks.innerHTML = `
      
      <div class="task-content">
        <div class="list-of-task">
        <div class="task" data-id="${id}">
        <input type="checkbox" class="tick">
        <div class="new-task-created">${taskNew}</div>
        <label class="due-date">${taskDate}</label>
        <label class="due-time">${taskTime}</label>
    </div>
    <div class="atcion-buttons">
        <button class="edit" data-id="">Edit</button>
        <button class="delete" data-id="">Delete</button>
    </div>
</div>`
storeList();
taskList.push(tasks);
el.list.appendChild(tasks);

};

//event listner that listens for add button.
function addTask() {
  
  creatTask();
}

//function that stores task list.
function storeList(){
  listData = JSON.stringify(taskList);
  localStorage.setItem('storage_key', taskList);

  list = localStorage.getItem('storage_key');
  newList = JSON.parse(list);
}

【问题讨论】:

  • 那么你现在真正的问题是什么?

标签: javascript local-storage


猜你喜欢
  • 1970-01-01
  • 2012-11-29
  • 2015-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-23
相关资源
最近更新 更多