如何在函数调用时向表添加数据

时间:2019-02-25 19:32:33

标签: javascript html electron

我当前正在尝试在我创建的表中添加一些数据,但是它似乎无法正常工作,并且也不会输出错误,我选择了错误的表还是添加了错误的数据?任何建议将不胜感激。

html表格:

  <div>
      <table id="requestContents">
        <tr>
          <th>Request Type</th>
          <th>Blood Type</th>
          <th>Notice</th>
        </tr>
      </table>
    </div>

Js:

  <script type="text/javascript">

    const electron = require('electron'); // declared once, no need to be decalerd again
    const { ipcRenderer } = electron;

    const table = document.getElementById("requestContents")
    console.log(table);

    ipcRenderer.on('Request:DonorInformation', function(e, requestType, bloodType, Notice) {

      const createRow = document.createElement('tr')
      const requestTypeAdd = document.createElement('td')
      const bloodTypeAdd = document.createElement('td')
      const noticeAdd = document.createElement('td')

      const requestTypeText = document.createTextNode(requestType)
      const bloodTypeText = document.createTextNode(bloodType)
      const NoticeText = document.createTextNode(Notice)

      requestTypeAdd.appendChild(requestTypeText)
      bloodTypeAdd.appendChild(bloodTypeText)
      noticeAdd.appendChild(NoticeText)

      createRow.appendChild(requestTypeAdd)
      createRow.appendChild(bloodTypeAdd)
      createRow.appendChild(noticeAdd)

      // Add tr to the table
      table.appendChild(createRow)

    })

  </script>

0 个答案:

没有答案