使最大数据记录相对于反作用中的过滤器



我有一个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);


相关内容

  • 没有找到相关文章

最新更新