- HTML5 Web Application Development By Example Beginner's Guide
- J.M. Gustafson
- 143字
- 2021-08-13 16:50:28
Time for action – loading the task list
Now that we've saved the new data model to localStorage
we need to update the loadTaskList()
method to load the data:
function loadTaskList() { var tasks = appStorage.getValue("taskList"); taskList = new TaskList(tasks); rebuildTaskList(); }
First we get the task array from localStorage
and pass that as a parameter into the TaskList
object's constructor. Then we call a new method, rebuildTaskList()
to create the task elements in the DOM:
function rebuildTaskList() { // Remove any old task elements $("#task-list").empty(); // Create DOM elements for each task taskList.each(function(task) { addTaskElement(task); }); }
First we remove any old elements from the task list element using the jQuery empty()
method. Then we use the each()
method that we implemented in the TaskList
object to iterate over the tasks and call addTaskElement()
for each one to build the task elements.
推薦閱讀
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- Visual C++串口通信開發入門與編程實踐
- C# Programming Cookbook
- 匯編語言程序設計(第2版)
- PLC編程及應用實戰
- Monitoring Elasticsearch
- Serverless架構
- Node.js Design Patterns
- Getting Started with LLVM Core Libraries
- MySQL從入門到精通(軟件開發視頻大講堂)
- PLC應用技術(三菱FX2N系列)
- Visual Basic程序設計習題與上機實踐
- Python大學實用教程
- 動手打造深度學習框架
- C++從入門到精通(第6版)