【问题标题】:How to flag certain rows of a table according to a value?如何根据值标记表的某些行?
【发布时间】:2017-11-22 01:37:38
【问题描述】:

我有一个 mongodb 集合,我正在使用 node.js 。我有一个“衣服”的集合,我在这张表中表示它的数据:

 <h2>Clothes</h2>       
  <table class="table">
    <thead>
      <tr>

        <th>price</th>
        <th> date </th>
        <th>Delete</th>
      </tr>
    </thead>
    <tbody>

        <% for(var i = 0; i < result.length; i++){%>
        <% if(result[i].type == "price"){%>
        <tr>

            <td><%= result[i].price %></td>
            <td><%= result[i].date %></td>
            <td>
                <form action="/delete-price" method="POST">
                    <input type="hidden" name="id" value="<%= result[i]._id %>">
                    <input type="submit" name="submit" value="Delete">
                </form>
            </td>
        </tr>
        <%}%>
        <%}%>

    </tbody>
  </table>

日期可以是一周中的任何一天。我的问题是,我想让用户通过表单提交一定的预算(这很容易),但我想同时比较所有行的所有费用

该表和数据库一样正常工作且功能齐全。

一个例子:

    Ex: If the user enters budget of 200$ , I should go to all the rows in 

"Clothes" , check the prices, if the prices is greater than the budget, this 

row should be flagged .

我怎样才能做到这一点?我对此很陌生。我尝试在 html 和 css 中执行此操作,但这是我的知识停止的地方

【问题讨论】:

    标签: html node.js mongodb


    【解决方案1】:

    你可能想尝试这样的事情,

    function flagClothes (clothes, userPrice){
     return clothes.map(function(price) {
       if(userPrice < price) return 'flagged' // I dont know exactly do you mean with flagged so i just return text, you can return anything.
    
     })
    };
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-22
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      • 2021-06-07
      • 2022-08-18
      • 2021-11-25
      • 2011-11-29
      相关资源
      最近更新 更多