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

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.

主站蜘蛛池模板: 建德市| 温泉县| 抚松县| 姜堰市| 兴隆县| 上蔡县| 永德县| 乌什县| 峨山| 涿州市| 三明市| 上高县| 兰考县| 商都县| 图们市| 友谊县| 霍邱县| 晋江市| 慈溪市| 阿拉善左旗| 正镶白旗| 芦山县| 英德市| 凯里市| 林州市| 东辽县| 德江县| 苍梧县| 延长县| 城口县| 白山市| 刚察县| 东至县| 色达县| 宝坻区| 新乡县| 苍溪县| 承德市| 甘南县| 昭苏县| 玉环县|