官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 沭阳县| 太保市| 建始县| 唐山市| 锦州市| 安溪县| 漠河县| 肇东市| 赞皇县| 舞阳县| 开封市| 洞头县| 于田县| 万州区| 长垣县| 游戏| 施甸县| 鹤岗市| 旺苍县| 茌平县| 繁峙县| 湖北省| 昌江| 定日县| 礼泉县| 定远县| 泾源县| 昔阳县| 西华县| 温泉县| 涡阳县| 乐陵市| 湟中县| 彭水| 班玛县| 浪卡子县| 丹凤县| 南涧| 常州市| 景洪市| 施甸县|