使用 mongoDB 进行 Reactjs 条件渲染

时间:2021-02-15 21:44:31

标签: json reactjs mongodb math statistics

我想在我的 Ap 中进行条件渲染,例如: 按性质或国家划分的总量,等等... 我怎样才能在我的应用程序中显示一些条件,例如: 自然数量的总和,例如:“ca”?

"_id": {
    "$oid": "6015d4d94dce3b095867175b"
},
"nature": "ebit",
"country": "france",
"year": 2020,
"amount": 20000,
"comments": [],
"__v": 0
}

{
"_id": {
    "$oid": "6015d5064dce3b095867175c"
},
"nature": "ca",
"country": "france",
"year": 2019,
"amount": 30000,
"comments": [],
"__v": 0
}

{
"_id": {
    "$oid": "6015d5064dce3b095867175c"
},
"nature": "ca",
"country": "france",
"year": 2019,
"amount": 30000,
"comments": [],
"__v": 0
}
{
"_id": {
    "$oid": "6015d5064dce3b095867175c"
},
"nature": "ca",
"country": "germany",
"year": 2019,
"amount": 30000,
"comments": [],
"__v": 0
}

到目前为止我有这个:

 return (
      <div>
          <ul>
          {!isEmpty(posts[0]) && 
          <li>
            {posts.map((post) => post.amount).reduce((acc, curr) => acc + curr, 0)}
          </li>
            }
          </ul>
      </div>
    )

提前谢谢你,希望我的问题很清楚。

0 个答案:

没有答案