html 中的表格无缘无故地呈现逗号

问题描述 投票:0回答:1

html 中的表格无缘无故地呈现逗号我正在使用nodemailer 和 smtp google 服务器我觉得这是与 html 相关的东西,但我无法弄清楚

const mailOptions = {
    from: "[email protected]",
    to: "[email protected]",
    subject: "Issue Persisting for long time",
    html:
      "<h2>These are the issues persisting for long time</h2><ul> " +
      `<table style="border: 1px solid black;" >
    <thead>
      <tr>
        <th style="border: 1px solid black;">description</th>
        <th style="border: 1px solid black;">department</th>
        <th style="border: 1px solid black;">Location</th>
        <th style="border: 1px solid black;">Date</th>
      </tr>
    </thead>
    <tbody>
      ${data.map((item) => {
        return `
        <tr>
        <td>sdfsdf</td>
        <td>sdfsdf</td>
        <td>sdfsdf</td>
        <td>sdfsdf</td>
        </tr>`
      })}
    </tbody>
  </table>`,
  };
  transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
      res.send(error);
    } else {
      console.log(mailOptions.text);
      res.send("Email sent: " + info.response);
    }
  });
javascript html node.js mongodb nodemailer
1个回答
4
投票

您的

map
调用会在此处返回一个数组:

    <tbody>
      ${data.map((item) => {
        return `
        <tr>
        <td>sdfsdf</td>
        <td>sdfsdf</td>
        <td>sdfsdf</td>
        <td>sdfsdf</td>
        </tr>`
      })}
    </tbody>

数组的默认字符串表示形式是其每个元素的逗号分隔表示形式。

您可以通过自己对数组进行字符串化来修复它,例如将

.map(..)
更改为
.map(..).join("")

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.