EJS forEach迭代中的数据总数

时间:2019-02-26 14:30:52

标签: javascript node.js ejs

enter image description here 我想做的是计算循环为每个数据生成的EJS迭代过程中待处理,已批准和未批准的数量。

下面是示例代码

<% var totalUploads = 0, totalApproved = 0, totalDisapproved = 0,
                                                                    totalPending = 0;

                                                                     profileData.forEach(function(item, index){ 

                                                                     totalUploads += index;

                                                                      if(item.status === "approved"){totalApproved += 1}

                                                                      if(item.status === "disapproved"){totalDisapproved += 1}

                                                                      if(item.status === "pending"){totalPending += 1}

                                                                     }); %>
                                                                    <h3 class="m-b-10"><%= totalUploads %></h3>
                                                                    <p class="text-uppercase m-b-5 font-13 font-600">Total Uploads</p>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6 col-xl-3">
                                                                <div class="card-box bg-primary widget-flat border-primary text-white">
                                                                    <i class="fi-archive"></i>
                                                                    <h3 class="m-b-10"><%= totalPending %></h3>
                                                                    <p class="text-uppercase m-b-5 font-13 font-600">Pending</p>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6 col-xl-3">
                                                                <div class="card-box widget-flat border-success bg-success text-white">
                                                                    <i class="fi-check"></i>
                                                                    <h3 class="m-b-10"><%= totalApproved %></h3>
                                                                    <p class="text-uppercase m-b-5 font-13 font-600">Approved</p>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6 col-xl-3">
                                                                <div class="card-box bg-danger widget-flat border-danger text-white">
                                                                    <i class="fi-delete"></i>
                                                                    <h3 class="m-b-10"><%= totalDisapproved %></h3>
                                                                    <p class="text-uppercase m-b-5 font-13 font-600">Disapproved</p>
                                                                </div>

0 个答案:

没有答案