weixin_47204581 2021-05-06 22:12 采纳率: 87.5%
浏览 418
已采纳

html中<tr th:each = "">中能使用两个不同的变量吗?

<table class="table table-striped table-hover">
      <thead>
        <tr>
          <th><i class="fas fa-calendar"></i> Date Tweeted</th>
          <th><i class="fas fa-hashtag"></i> Tweet</th>
        </tr>
      </thead>
      <tbody>
        <tr th:each="d : ${dates}">
          <td th:text="${{d}}">Tweet Date</td>
        </tr>
        <tr th:each="t : ${tweets}">
          <td th:text="${{t}}">Tweets</td>
        </tr>
      </tbody>
    </table>

这是目前使用的代码,效果如下:

1

但预期效果应该是那行字符串在22这个数字的同一行,也就是归属在同一个<tr>内,请问有没有什么办法能把这两个<tr>部分结合起来或者其他方法能达成这种效果吗?谢谢!

  • 写回答

4条回答 默认 最新

  • 七宝文 2021-05-07 10:26
    关注

    html部分

    <table class="table table-striped table-hover">
          <thead>
            <tr>
              <th><i class="fas fa-calendar"></i> Date Tweeted</th>
              <th><i class="fas fa-hashtag"></i> Tweet</th>
            </tr>
          </thead>
          <tbody>
            <tr class="concatTr">
              
            </tr>
          </tbody>
    </table> 

    js部分 

    let tds=''
    dates.forEach(d=>{
        tds+=`<td>${d}</td>`
    }) 
    tweets.forEach(t=> {
        tds+=`<td>${t}</td>`
    });
    document.querySelector('.concatTr').innerHTML=tds;
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面