- 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.
推薦閱讀
- Vue 3移動Web開發與性能調優實戰
- PHP程序設計(慕課版)
- NLTK基礎教程:用NLTK和Python庫構建機器學習應用
- TestNG Beginner's Guide
- 人人都是網站分析師:從分析師的視角理解網站和解讀數據
- Kotlin Standard Library Cookbook
- Python機器學習算法與實戰
- Mastering Android Game Development
- HTML5從入門到精通(第4版)
- Java程序員面試筆試寶典(第2版)
- Java SE實踐教程
- Learning Node.js for .NET Developers
- ExtJS Web應用程序開發指南第2版
- JSP程序設計實例教程(第2版)
- Learning Python Data Visualization