Solution Review: Import Tasks in the To-Do List from a Server
This review provides a detailed explanation to solve the 'Import Tasks in the To-Do List from a Server' challenge.
We'll cover the following
Solution
Explanation
-
In line 3, we make a GET request to the server with a URL of https://5f28559af5d27e001612eebf.mockapi.io/tasks/.
-
In line 20, we specify the response’s expected data type from the server.
-
In line 4, we define the callback function for the
get()
method, which is executed after the successful completion of the GET request.- In the callback function (line 6), we extract the list of tasks from the server response object
data
with typeJSON
. - In the callback function (lines 8-18), we iterate the tasks one-by-one and add them to the end of the to-do list. The code for task addition is identical to that in the event handler for the “Add” button.
- In lines 9-17, we create a new task, add the done and delete buttons, and then add the task to the
notCompleted
class.
- In the callback function (line 6), we extract the list of tasks from the server response object