如何从对象中分离出一系列对象

How to separate a series of objects from the object

我正在使用 useReducer 这就是我所拥有的:

const initialState = {
    optionalFilter: {
      take: Math.round((window.innerHeight - 330) / 34),
      page: 1,
    },
    reportFilter: {
      searchItem:[],
      dateFilter: {
        StartDate:new Date(new Date().setDate(new Date().getDate() - 3100)),
        EndDate:new Date(),
      },
     
    }, 
  };
const reducer = (state, action) => {
    switch (action.type) {
      case "changeFilter":
        console.log("action",action.payload)
        return updateObject(state, {
          optionalFilter: updateObject(state.optionalFilter, {
            page: 1,
          }),
          reportFilter: updateObject(state.reportFilter, {
            searchItem: action.payload,
          }),
          reportFilter: updateObject(state.reportFilter.dateFilter, {
            StartDate:new Date(new Date().setDate(new Date().getDate() - 3100)),
        EndDate:new Date(),
          }),
        });
    }
  };

当我想应用filler的时候。比如我得到一个console of action的时候,我有这样一个数组:

console of action.payload==>[{property:"StartDate: , value:"12.12.12"}{property:"EndDate: , value:"13.13.12"}{property:"Title: , value:"test"}{property:"name": , value:"name"}]

我应该如何在 state.reportFilter.dateFilter 中设置 StartDate 和 EndDate 值并将其余值放入 searchItem数组

请通过替换 reducer 方法尝试此代码

const reducer = (state, action) => {
    switch (action.type) {
      case "changeFilter":
        console.log("action",action.payload)
        return updateObject(state, {
          optionalFilter: updateObject(state.optionalFilter, {
            page: 1,
          }),
          reportFilter: updateObject(state.reportFilter, {
            searchItem: action.payload.filter(val => val.property !== "StartDate" &&  val.property !== "EndDate");,
          }),
          reportFilter: updateObject(state.reportFilter.dateFilter, {
            StartDate:action.payload.find(val => val.property === "StartDate").value,
        EndDate:action.payload.find(val => val.property === "EndDate").value,
          }),
        });
    }
  };