Javascript / NodeJS forEach循环

时间:2017-12-17 02:07:24

标签: javascript node.js

我有这个forEach循环:

 <% users.forEach(function(user) { %>
   <tr>
     <td><%= user.studio %></td>
     <td><%= user.name %></td>
     <td><%= user.email %></td>
     <td><%= user.username %></td>
     <td>
     <% user.comments.forEach(function(comment) { %>
         <%= comment.collected %>
     <% }); %>
     </td>
    <td ><a class="btn btn-primary" href="/users/<%= user._id %>">More Info</a></td>
<% }); %>

我想要做的只是向'At Reception'显示comment.collected作为var UserSchema = new mongoose.Schema({ username: {type: String, unique: true, required: true}, name: {type: String, required: true}, email: {type: String, unique: true, required: true}, password: String, studio: {type: String, required: true}, resetPasswordToken: String, resetPasswordExpires: Date, comments: [ { quantity: String, received: { type: Date, default: Date.now }, collected: { type: String, default: "At Reception" } } ], isAdmin: {type: Boolean, default: false} }); 的值的用户,但我在查明如何执行此操作时遇到问题。任何帮助将不胜感激。

编辑:

有问题的UserSchema如下所示:

 'data.frame':  2285 obs. of  2 variables:
  $ Date : Date, format: "2017-12-14" "2017-12-13" ...
  $ Price: num  16234 16250 16650 16470 14691 ...

1 个答案:

答案 0 :(得分:0)

您应首先过滤数组:

    rdd.map({
    Try(fn) match{
case Success: _
case Failure:<<Record with error flag>>
}).filter(record.errorflag==null)

注意:以上代码显示至少有一条评论为<% users.filter(function(user) { // filter only users return user.comments.some(function(comment) { // that some (at least one) of their comments return comment.collected === "At Reception"; // have its collected property equal to "At Reception" }); }).forEach(function(user) { %> ... 的用户。如果您只想显示其所有评论的收集属性等于comment.collect === 'At Reception'的用户,请使用'At Reception'代替Array#every

Array#some