js에서 열심히 작성했는데, 결국 java에서 처리하게 되었음. 혹시 몰라서 코드 냄겨놓기
c_TYPE: function(data){
let isDrctType = data.filter(x => x.DRCT_TYPE === 1 );
console.log('isDrctType ::: ', isDrctType);
if( isDrctType.length === 0 ) console.log('isDrctType : 0이네요 ', isDrctType); return ;
console.log("cmr_DRCT_TYPE [1] data : ", data);
const result = data.map(item => {
const newItem = { ...item };
const matches = data.filter(x => x.ACSR_ID === item.ACSR_ID && x.CRSRD_ACSR_ID !== item.CRSRD_ACSR_ID);
//console.log("cmr_DRCT_TYPE [2] matches : ", matches);
if (matches.length > 0) {
const secondItem = matches[0];
newItem.CMR_ID_second = secondItem.CMR_ID;
newItem.CMR_NM_second = secondItem.CMR_NM;
newItem.DRCT_TYPE_second = secondItem.DRCT_TYPE;
}
return newItem;
});
// 합치기!! 5개를 4개로 줄임
const uniqueACSRIDs = [...new Set(data.map(item => item.ACSR_ID))];
const finalResult = [];
uniqueACSRIDs.forEach( id => {
const filteredItems = result.filter(item => item.ACSR_ID === id);
if (filteredItems.length > 1) {
finalResult.push(filteredItems[0]);
} else if (filteredItems.length === 1) {
finalResult.push(filteredItems[0]);
}
});
return finalResult;
},
728x90
300x250