- 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>
- Mastering QGIS
- MATLAB 2020 從入門到精通
- MySQL 8 DBA基礎(chǔ)教程
- Java加密與解密的藝術(shù)
- 用Flutter極速構(gòu)建原生應(yīng)用
- OpenShift在企業(yè)中的實(shí)踐:PaaS DevOps微服務(wù)(第2版)
- C語言實(shí)驗(yàn)指導(dǎo)及習(xí)題解析
- Python忍者秘籍
- Modern C++ Programming Cookbook
- Java并發(fā)編程之美
- Java Web從入門到精通(第2版)
- Building a Media Center with Raspberry Pi
- Android初級(jí)應(yīng)用開發(fā)
- PHP 7 Programming Blueprints
- HTML5程序開發(fā)范例寶典