...
/Solution Review: Handling Employee Details
Solution Review: Handling Employee Details
Review the solution for the IndexedDB challenge on handling employee details.
We'll cover the following...
Solution
The code below contains the solution for all the tasks from the previous lesson:
Code explanation
Task 1: We create the Company
database and add an Employee
object store.
Line 2: We retrieve the button with the
init_db
ID and store it in a variable.Line 3: We create a variable to hold the database object that can be used in all the functions.
Line 4: We add the click event listener to the
initDatabase
button.Line 6: Inside the click handler, we use the
open()
method to open a new connection to theCompany
database. A new database will be created if the database isn’t already present. During the new database creation, we trigger theupgradeneeded
event.Lines 7–10: We add the
success
event handler to the open database request. Inside the event handler, we get the ...