- JavaScript by Example
- Dani Akash S
- 236字
- 2021-07-02 18:39:07
Loading the tasks from data
The first thing we want to do in our application is to load the tasks dynamically from a set of data. Let's declare a class variable that contains the data for tasks along with methods needed to pre-populate the tasks. ES6 does not provide a direct way to declare class variables. We need to declare variables using the constructor. We also need a function to load tasks into the HTML elements. So, we'll create a loadTasks() method:
class ToDoClass {
constructor() {
this.tasks = [
{task: 'Go to Dentist', isComplete: false},
{task: 'Do Gardening', isComplete: true},
{task: 'Renew Library Account', isComplete: false},
];
this.loadTasks();
}
loadTasks() {
}
}
The tasks variable is declared inside the constructor as this.tasks, which means the tasks variable belongs to this (ToDoClass). The variable is an array of objects that contain the task details and its completion status. The second task is set to be completed. Now, we need to generate an HTML code for the data. We'll reuse the code of the <li> element from the HTML to generate a task dynamically:
<li class="list-group-item checkbox">
<div class="row">
<div class="col-md-1 col-xs-1 col-lg-1 col-sm-1 checkbox">
<label><input type="checkbox" value="" class="" checked></label>
</div>
<div class="col-md-10 col-xs-10 col-lg-10 col-sm-10 task-text complete">
First item
</div>
<div class="col-md-1 col-xs-1 col-lg-1 col-sm-1 delete-icon-area">
<a class="" href="/"><i class="delete-icon glyphicon glyphicon-trash"></i></a>
</div>
</div>
</li>
- The Complete Rust Programming Reference Guide
- 程序員面試白皮書
- Arduino by Example
- Mastering Selenium WebDriver
- PowerCLI Cookbook
- Java軟件開發基礎
- MySQL數據庫管理與開發(慕課版)
- Highcharts Cookbook
- CoffeeScript Application Development Cookbook
- “笨辦法”學C語言
- Kotlin進階實戰
- Java多線程并發體系實戰(微課視頻版)
- Building UIs with Wijmo
- Zend Framework 2 Cookbook
- 生成藝術:Processing視覺創意入門