HTML中的表格无缘无故地渲染了一个逗号。

huangapple go评论70阅读模式
英文:

the table in html is rendering a comma without any reason

问题

I have translated the code portion for you:

const mailOptions = {
    from: "xyz@gmail.com",
    to: "yzx@gmail.com",
    subject: "Issue Persisting for a long time",
    html:
      "<h2>These are the issues persisting for a 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);
    }
  });

If you have any other code sections to translate or need further assistance, please let me know.

英文:

the table in html is rendering a comma without any reason i am using nodemailer and smtp google server i feel it is something with respect to the html but i am not able to figure out

HTML中的表格无缘无故地渲染了一个逗号。

const mailOptions = {
    from: &quot;xyz@gmail.com&quot;,
    to: &quot;yzx@gmail.com&quot;,
    subject: &quot;Issue Persisting for long time&quot;,
    html:
      &quot;&lt;h2&gt;These are the issues persisting for long time&lt;/h2&gt;&lt;ul&gt; &quot; +
      `&lt;table style=&quot;border: 1px solid black;&quot; &gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th style=&quot;border: 1px solid black;&quot;&gt;description&lt;/th&gt;
        &lt;th style=&quot;border: 1px solid black;&quot;&gt;department&lt;/th&gt;
        &lt;th style=&quot;border: 1px solid black;&quot;&gt;Location&lt;/th&gt;
        &lt;th style=&quot;border: 1px solid black;&quot;&gt;Date&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      ${data.map((item) =&gt; {
        return `
        &lt;tr&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;/tr&gt;`
      })}
    &lt;/tbody&gt;
  &lt;/table&gt;`,
  };
  transporter.sendMail(mailOptions, (error, info) =&gt; {
    if (error) {
      res.send(error);
    } else {
      console.log(mailOptions.text);
      res.send(&quot;Email sent: &quot; + info.response);
    }
  });

答案1

得分: 3

Your map invocation returns an array here:

    &lt;tbody&gt;
      ${data.map((item) =&gt; {
        return `
        &lt;tr&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;/tr&gt;`
      })}
    &lt;/tbody&gt;

The default string representation of an array is the comma-separated representation of each of its elements.

You can fix it by stringifying the array yourself, e.g. change the .map(..) to .map(..).join(&quot;&quot;).

英文:

Your map invocation returns an array here:

    &lt;tbody&gt;
      ${data.map((item) =&gt; {
        return `
        &lt;tr&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;td&gt;sdfsdf&lt;/td&gt;
        &lt;/tr&gt;`
      })}
    &lt;/tbody&gt;

The default string representation of an array is the comma-separated representation of each of its elements.

You can fix it by stringifying the array yourself, e.g. change the .map(..) to .map(..).join(&quot;&quot;).

huangapple
  • 本文由 发表于 2023年4月13日 21:31:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76006050.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定