0

我正在尝试为反应表创建一个循环。我有一个功能 getMyData

const getMyData =()=> {
  const arrAvg = arr => arr.reduce((a, b) => a + b, 0) / arr.length;
  let result = {
    today: null,
    average: null,
    name: null,
  }

  for (var key in data.users) {
    const start =  moment(data.users[key].lastUpdated)
    const end = moment();
    const range = moment.range(start, end);
    const days = range.diff('days');

    console.log('The days are ',days);

    if (days >= 0 && days < 7) {
      result.today = data.users[key].availabilityArray[days];
      result.average = arrAvg(data.users[key].availabilityArray.splice(days + 1));
      result.name = data.users[key].name;
      var absentVal = result.absent=   data.users[key].absent
    }

    console.log('Executing this command ', key);
    if (absentVal===true){
      return {result}
    }
    console.log('End of return result',result );
  }
}

然后导出函数

const range1 = len => {
  const arr = [];
  for (let i = 0; i < len; i++) {
    arr.push(i);
  }

  console.log('The arr is ', arr);
  return arr;
};

export function makeData(len = 2){
  return range1(len).map(d=> {
    return getMyData();
  });
}
4

0 回答 0