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

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.

主站蜘蛛池模板: 富顺县| 景德镇市| 巴中市| 耿马| 武功县| 河南省| 囊谦县| 宝山区| 溧阳市| 历史| 阜平县| 玉门市| 金堂县| 南通市| 千阳县| 专栏| 电白县| 辛集市| 虞城县| 朝阳县| 连平县| 宿松县| 应城市| 固原市| 桃园县| 潍坊市| 石林| 唐河县| 宁陕县| 方正县| 阳春市| 京山县| 望城县| 盐山县| 奉化市| 巴楚县| 苍梧县| 林芝县| 临沧市| 连云港市| 乡宁县|