- 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.
推薦閱讀
- Learning Python Web Penetration Testing
- C語言程序設(shè)計案例教程(第2版)
- Building a Game with Unity and Blender
- Microsoft Application Virtualization Cookbook
- PHP基礎(chǔ)案例教程
- 程序員數(shù)學(xué):用Python學(xué)透線性代數(shù)和微積分
- The Computer Vision Workshop
- PySide GUI Application Development(Second Edition)
- Serverless架構(gòu)
- 前端HTML+CSS修煉之道(視頻同步+直播)
- 微信小程序全棧開發(fā)技術(shù)與實戰(zhàn)(微課版)
- JavaScript腳本特效編程給力起飛
- Flowable流程引擎實戰(zhàn)
- 超簡單:用Python讓Excel飛起來(實戰(zhàn)150例)
- Getting Started with React VR