m0_71681226 2022-10-24 20:38 采纳率: 100%
浏览 43
已结题

我将数据在JS中存储到了一个数组当中,在html表格里导入这些数组时显示undefined。

我将数据在JS中存储到了一个数组当中,在html表格里导入这些数组时显示undefined。

数组:

var list = [{ "Id": '0', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
    { "Id": '1', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
    { "Id": '2', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
    { "Id": '3', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
    { "Id": '4', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" }];

html:

<html lang="zh"  >
<head></head>
 <script type="text/javascript" src="src/qwe.js"></script>
<body>
    <div>
        <table id="bookstoTY" width="100%" style="border: beige 1px solid">
        </table>
            <h1 style="margin-left: 39%;">
                online bookstore
            </h1>
        <h2 style="margin-top: 80px;margin-left: 39%;">
        Buy books now and save up to 20%.
        </h2>
    </div>
    <table 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>
 let table1=document.getElementById("table1");
 for(let i=0;i<list.length;i++){
 let newRow=table1.insertRow();
 
 let newCell1=newRow.insertCell();
 newCell1.innerHTML=list[i][0];
 
 let newCell2=newRow.insertCell();
 newCell2.innerHTML=list[i][1];
 }

</script>


</body>
</html>

错误:

img

请问该怎么解决这个问题。

  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2022-10-24 20:57
    关注

    要调用对应的属性,其他属性同理

    <html lang="zh">
    <head>
    </head>
    <script type="text/javascript" src="src/qwe.js"></script>
    <body>
        <div>
            <table id="bookstoTY" width="100%" style="border: beige 1px solid">
            </table>
            <h1 style="margin-left: 39%;">
                online bookstore
            </h1>
            <h2 style="margin-top: 80px;margin-left: 39%;">
                Buy books now and save up to 20%.
            </h2>
        </div>
        <table 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>
            var list = [{ "Id": '0', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
            { "Id": '1', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
            { "Id": '2', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
            { "Id": '3', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
            { "Id": '4', "FirstName": "Guuss", "LastName": "Hsidjsi", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" }];
            let table1 = document.getElementById("table1");
            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;
            }
    
        </script>
    
    
    </body>
    </html>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月24日
  • 已采纳回答 10月24日
  • 创建了问题 10月24日

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目