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

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.

主站蜘蛛池模板: 达尔| 藁城市| 卢龙县| 晋中市| 通州区| 宿迁市| 兴国县| 丰城市| 沾益县| 新河县| 泗水县| 扶沟县| 台州市| 小金县| 平顺县| 贵南县| 枣阳市| 保亭| 晋城| 图木舒克市| 北安市| 红河县| 乌拉特中旗| 久治县| 汕头市| 赤水市| 绥棱县| 明溪县| 二连浩特市| 柞水县| 沁阳市| 红原县| 云南省| 嵊泗县| 唐山市| 玛多县| 赤水市| 兴海县| 钟山县| 翁源县| 隆安县|