【问题标题】:Add a new table row to existing table but before the first row将新表行添加到现有表但在第一行之前
【发布时间】:2020-04-23 11:58:35
【问题描述】:

我正在尝试制作一个交易详情页面,我怎样才能使交易表上的新输入表行排在前一个之前?我使用 node、mongo、mongoose 和 javascript 和 ejs

<section id="transactions">

        <div class="mx-5 my-5">

          <table>
            <tr>
              <th>Transaction ID</th>
              <th>Beneficiary Details</th>
              <th>Timestamp</th>
              <th>More</th>
            </tr>



            <% transactions.forEach(function(transaction) { %>
              <tr>
                <td><%= transaction._id %></td>
                <td> <%= transaction.beneficiaryName %> <%= transaction.beneficiaryBank %> <%= transaction.beneficiaryAccountNumber %> <%= transaction.transferAmount %></td>
                <td><%= transaction.time %></td>
                <td><a href="<%= transaction._id %>"></a></td>
              </tr>

            <% }) %>


          </table>


        </div>

【问题讨论】:

    标签: html css node.js ejs


    【解决方案1】:

    如果你是从交易中生成列表,我猜它是一个对象数组,你可以使用:

    transactions.unshift({<newObject>})
    

    将其添加到数组的开头

    如果你想用 JQuery 来做,使用:

    $('table > tbody > tr:first').before('<tr><td>Stuff</td></tr>');
    

    【讨论】:

    • 我在我的节点中使用了第一个选项,它运行良好.. 谢谢。
    猜你喜欢
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    相关资源
    最近更新 更多