我试图通过从MySQL提取数据来创建表,但数据未显示。而且没有错误显示消息,所以我不知道我做错了什么。
**我尝试使用Postman查看是否正确使用了它。该程序可以显示信息页面。
这是HTML代码:
<div class="table-responsive">
<table class="table table-striped" id="employee_table">
<thead>
<tr>
<th scope="col">Employee_ID</th>
<th scope="col">FirstName</th>
<th scope="col">LastName</th>
<th scope="col">Gender</th>
<th scope="col">Dateofbirth</th>
<th scope="col">BloodGroup</th>
<th scope="col">Address</th>
<th scope="col">Email</th>
<th scope="col">ContactNo</th>
<th scope="col">JoiningDate</th>
<th scope="col">EmployeeType</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
这是JavaScript代码:
let employeeList = document.querySelector("#employee_table > tbody");
let employee = [];
const loadEmployee = () => {
userGet().then(data => {
employee = data
generateTableEmployee()
})
}
const generateTableEmployee = () => {
employeeList.innerHTML = "";
employee.forEach(employees => {
let tr = document.createElement("tr");
let th = document.createElement("th");
th.setAttribute("scope", "row");
th.innerHTML = employees.Employee_ID;
let tdEmployee_ID = document.createElement("td");
tdEmployee_ID.innerHTML = employees.Employee_ID;
let tdFName = document.createElement("td");
tdFName.innerHTML = employees.FName;
let tdLName = document.createElement("td");
tdLName.innerHTML = employees.LName;
let tdgender = document.createElement("td");
tdgender.innerHTML = employees.gender;
let tdDateofbirth = document.createElement("td");
tdDateofbirth.innerHTML = employees.Dateofbirth;
let tdBloodGroup = document.createElement("td");
tdBloodGroup.innerHTML = employees.BloodGroup;
let tdAddress = document.createElement("td");
tdAddress.innerHTML = employees.Address;
let tdEmail = document.createElement("td");
tdEmail.innerHTML = employees.Email;
let tdContactNo = document.createElement("td");
tdContactNo.innerHTML = employees.ContactNo;
let tdJoiningDate = document.createElement("td");
tdJoiningDate.innerHTML = employees.JoiningDate;
let tdEmployeeType = document.createElement("td");
tdEmployeeType.innerHTML = employees.EmployeeType;
tr.appendChild(th)
tr.appendChild(tdEmployee_ID)
tr.appendChild(tdFName)
tr.appendChild(tdLName)
tr.appendChild(tdgender)
tr.appendChild(tdDateofbirth)
tr.appendChild(tdBloodGroup)
tr.appendChild(tdAddress)
tr.appendChild(tdEmail)
tr.appendChild(tdContactNo)
tr.appendChild(tdJoiningDate)
tr.appendChild(tdEmployeeType)
employeeList.appendChild(tr);
})
}
或者我在另一个文件中写了错误的代码。