gpt4 book ai didi

reactjs - 为 react 中的过滤器带来最大数据记录

转载 作者:行者123 更新时间:2023-12-04 08:48:05 24 4
gpt4 key购买 nike

我有一个 JSON 对象,任何用户都可以在其中提交应用程序,并且可以由任何用户操作。应用程序获得批准后,我需要显示最大日期“建议”和最大日期“已批准”。我的 JSON 对象是

var histData = [{
"EXECUTION_STATE_CODE":"PROPOSED",
"EXECUTION_BY":"User1",
"EVENT_ID":4893664,
"CREATED_ON":"2020-09-25T18:57:33.000Z",
},
{
"EXECUTION_STATE_CODE":"REJECTED",
"EXECUTION_BY":"ADMINUser1",
"EVENT_ID":4893665,
"CREATED_ON":"2020-09-25T19:57:33.000Z",
},
{
"EXECUTION_STATE_CODE":"MODIFIED",
"EXECUTION_BY":"User12",
"EVENT_ID":4893669,
"CREATED_ON":"2020-09-25T20:12:33.000Z",
},
{
"EXECUTION_STATE_CODE":"PROPOSED",
"EXECUTION_BY":"User12",
"EVENT_ID":4893670,
"CREATED_ON":"2020-09-25T20:32:33.000Z",
},
{
"EXECUTION_STATE_CODE":"APPROVED",
"EXECUTION_BY":"ADMINUser22",
"EVENT_ID":4893672,
"CREATED_ON":"2020-09-25T18:57:33.000Z",
}];
我试过的代码如下但不起作用。
let var1 = new Date(Math.max.apply(null, histData.map(function(e) {
console.log("object", e)
if(e.EXECUTION_STATE_CODE==="PROPOSED"){

return e.EXECUTED_ON;
}
预期结果是
Application 
Proposer : User12
Approved : AdminUser22
请帮忙

最佳答案

考虑到您有对象数组,我将其命名为 histData

var histData = [{
"EXECUTION_STATE_CODE":"PROPOSED",
"EXECUTION_BY":"User1",
"EVENT_ID":4893664,
"CREATED_ON":"2020-09-25T18:57:33.000Z",
},
{
"EXECUTION_STATE_CODE":"REJECTED",
"EXECUTION_BY":"ADMINUser1",
"EVENT_ID":4893665,
"CREATED_ON":"2020-09-25T19:57:33.000Z",
},
{
"EXECUTION_STATE_CODE":"MODIFIED",
"EXECUTION_BY":"User12",
"EVENT_ID":4893669,
"CREATED_ON":"2020-09-25T20:12:33.000Z",
},
{
"EXECUTION_STATE_CODE":"PROPOSED",
"EXECUTION_BY":"User12",
"EVENT_ID":4893670,
"CREATED_ON":"2020-09-25T20:32:33.000Z",
},
{
"EXECUTION_STATE_CODE":"APPROVED",
"EXECUTION_BY":"ADMINUser22",
"EVENT_ID":4893672,
"CREATED_ON":"2020-09-25T18:57:33.000Z",
}];



var maxPropsed = histData.filter(h => h.EXECUTION_STATE_CODE==="PROPOSED").reduce((a, b) => {
return new Date(a.CREATED_ON) > new Date(b.CREATED_ON) ? a : b;
},{}).EXECUTION_BY;

var maxApproved = histData.filter(h => h.EXECUTION_STATE_CODE==="APPROVED").reduce((a, b) => {
return new Date(a.CREATED_ON) > new Date(b.CREATED_ON) ? a : b;
},{}).EXECUTION_BY;




    var histData = [{
"EXECUTION_STATE_CODE":"PROPOSED",
"EXECUTION_BY":"User1",
"EVENT_ID":4893664,
"CREATED_ON":"2020-09-25T18:57:33.000Z",
},
{
"EXECUTION_STATE_CODE":"REJECTED",
"EXECUTION_BY":"ADMINUser1",
"EVENT_ID":4893665,
"CREATED_ON":"2020-09-25T19:57:33.000Z",
},
{
"EXECUTION_STATE_CODE":"MODIFIED",
"EXECUTION_BY":"User12",
"EVENT_ID":4893669,
"CREATED_ON":"2020-09-25T20:12:33.000Z",
},
{
"EXECUTION_STATE_CODE":"PROPOSED",
"EXECUTION_BY":"User12",
"EVENT_ID":4893670,
"CREATED_ON":"2020-09-25T20:32:33.000Z",
},
{
"EXECUTION_STATE_CODE":"APPROVED",
"EXECUTION_BY":"ADMINUser22",
"EVENT_ID":4893672,
"CREATED_ON":"2020-09-25T18:57:33.000Z",
}];



var maxPropsed = histData.filter(h => h.EXECUTION_STATE_CODE==="PROPOSED").reduce((a, b) => {
return new Date(a.CREATED_ON) > new Date(b.CREATED_ON) ? a : b;
},{}).EXECUTION_BY;

var maxApproved = histData.filter(h => h.EXECUTION_STATE_CODE==="APPROVED").reduce((a, b) => {
return new Date(a.CREATED_ON) > new Date(b.CREATED_ON) ? a : b;
},{}).EXECUTION_BY;


console.log("maxPropsed: ", maxPropsed);

console.log("maxApproved:", maxApproved);


关于reactjs - 为 react 中的过滤器带来最大数据记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64212898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com