我想要制作一个⼀种将患者标记为紧急情况并显⽰所有紧急患者列表的⽅法。
患者信息储存在一个数组里
var list = [{ "Id": '0', "FirstName": "Stark", "LastName": "Bill", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
{ "Id": '1', "FirstName": "Shown", "LastName": "Jenny", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
{ "Id": '2', "FirstName": "Geogrge", "LastName": "Hash", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
{ "Id": '3', "FirstName": "Intwre", "LastName": "zaiwoo", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
{ "Id": '4', "FirstName": "Niko", "LastName": "baby", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" }];
我的想法是定义一个新数组,当点击储存按钮时使用slice方法储存这个数组再把它存放在新数组中,再在html中创建一个新的表,把新数组里的数据遍历到新表里。
这是我做的储存患者信息表的代码:
javascript:
function refreshList(){
let table1=document.getElementById("table1");
while(table1.hasChildNodes()){
table1.removeChild(table1.lastChild);
}
let newHeaderRow=table1.insertRow();
let newCell1=newHeaderRow.insertCell();
newCell1.innerHTML="Patient ID*";
let newCell2=newHeaderRow.insertCell();
newCell2.innerHTML="First name*";
let newCell3=newHeaderRow.insertCell();
newCell3.innerHTML="Last name*";
let newCell4=newHeaderRow.insertCell();
newCell4.innerHTML="Date of birth *";
let newCell5=newHeaderRow.insertCell();
newCell5.innerHTML="Gender*";
let newCell6=newHeaderRow.insertCell();
newCell6.innerHTML="Primary insurance*";
let newCell7=newHeaderRow.insertCell();
newCell7.innerHTML="Address *";
let newCell8=newHeaderRow.insertCell();
newCell8.innerHTML="Contact number *";
let newCell9=newHeaderRow.insertCell();
newCell9.innerHTML="Next of kin";
let newCell10=newHeaderRow.insertCell();
newCell10.innerHTML="HANDING";
for(let i=0;i<list.length;i++){
let newRow=table1.insertRow();
let newCell1=newRow.insertCell();
newCell1.innerHTML=list[i].Id;
let newCell2=newRow.insertCell();
newCell2.innerHTML=list[i].FirstName;
let newCell3=newRow.insertCell();
newCell3.innerHTML=list[i].LastName;
let newCell4=newRow.insertCell();
newCell4.innerHTML=list[i].DateOfBirth;
let newCell5=newRow.insertCell();
newCell5.innerHTML=list[i].Gender;
let newCell6=newRow.insertCell();
newCell6.innerHTML=list[i].PrimaryInsurance;
let newCell7=newRow.insertCell();
newCell7.innerHTML=list[i].Address;
let newCell8=newRow.insertCell();
newCell8.innerHTML=list[i].ContactNumber;
let newCell9=newRow.insertCell();
newCell9.innerHTML=list[i].NextOfKin;
let newCell10=newRow.insertCell();
newCell10.innerHTML="<input type='button' value='urgent'>";
}
}
html:
<table width"100%" border="1" id="table1">
<tr>
<td>Patient ID*</td>
<td>First name*</td>
<td>Last name*</td>
<td>Date of birth *</td>
<td>Gender*</td>
<td>Primary insurance*</td>
<td>Address *</td>
<td>Contact number *</td>
<td>Next of kin</td>
<td>HANDING</td>
</tr>
</table>
<script>
refreshList();
</script>
运行结果:
我在写将患者设为紧急的代码:
var urgent = [];
function GetUrgentPatient(list, urgentID){
for(let i=0; i<list.legth; i++){
if (list[i].Id === urgentId){
var urgent=list.slice(urgentId.value,urgentId.value+1);
console.log(urgent);
}
}
return list;
}
function UrgentPatient(){
var urgentId=document.getElementById("");
}
我无法在点击按钮时获得html表里那个按钮那一行的患者的ID,因此无法在 GetUrgentPatient方法里对比是否list[i].Id === urgentId,我本来想用getElementById方法来获取这个ID,但我发现我无法在html表里添加ID,因为我的按钮是用innerHTML遍历生成的。
请问该怎么解决这个问题让患者标记为紧急情况并显⽰所有紧急患者列表?