Ract-Native屏幕日历不显示日期数组

时间:2018-08-16 12:00:00

标签: arrays react-native react-native-calendars

我正在使用React-Native-Calenders

  

https://github.com/wix/react-native-calendars

当我尝试通过数组在日历上显示日期时,它不显示该值。但是,如果我使用一个变量,它将起作用。例如:

setCalender(response){

  //Set Variables:
  var tmpStartDate = [];
  var tmpEndDate = [];
  var tmpMidDate = [];
  var diffDays = [];

  //Get the start and end dates:
  for(var i=0; i<response.length; i++){
    tmpStartDate[i] = response[i].date_start;
    tmpEndDate[i] = response[i].date_end;
  }

  //Calculate the time difference:
  for(var i=0; i<tmpStartDate.length; i++){
    var date1 = new Date(tmpStartDate[i]);
    var date2 = new Date(tmpEndDate[i]);
    var timeDiff = Math.abs(date2.getTime() - date1.getTime());
    diffDays[i] = Math.ceil(timeDiff / (1000 * 3600 * 24));
  }

  var TempMidDate = "";
  var tempDate = [];
  for(var i=0; i<diffDays[0]; i++){
    var date = new Date(tmpStartDate[0]);
    tmpMidDate[i] = date.setDate(date.getDate()+i);

    var date1 = new Date(tmpMidDate[i]);
    var tmpDate = [
      date1.getFullYear().toString(),
      (date1.getMonth()+1).toString(),
      date1.getDate().toString(),
    ];
    TempMidDate = tmpDate[0]+"-"+tmpDate[1]+"-"+tmpDate[2]; //Array
    tempDate[i] = TempMidDate;

  }

this.setState({StartDate: tmpStartDate, EndDate: tmpEndDate, TimeP: diffDays, MidDate: tempDate});
}

这里是变量而不是数组:

setCalender(response){

  //Set Variables:
  var tmpStartDate = [];
  var tmpEndDate = [];
  var tmpMidDate = [];
  var diffDays = [];

  //Get the start and end dates:
  for(var i=0; i<response.length; i++){
    tmpStartDate[i] = response[i].date_start;
    tmpEndDate[i] = response[i].date_end;
  }

  //Calculate the time difference:
  for(var i=0; i<tmpStartDate.length; i++){
    var date1 = new Date(tmpStartDate[i]);
    var date2 = new Date(tmpEndDate[i]);
    var timeDiff = Math.abs(date2.getTime() - date1.getTime());
    diffDays[i] = Math.ceil(timeDiff / (1000 * 3600 * 24));
  }

  var TempMidDate = "";
  var tempDate = [];
  for(var i=0; i<diffDays[0]; i++){
    TempMidDate = "2016-02-23"; //Variable
    tempDate[i] = TempMidDate;
  }

this.setState({StartDate: tmpStartDate, EndDate: tmpEndDate, TimeP: diffDays, MidDate: tempDate});
}

可能我真的很想念我,但是我无法解决这个问题。

0 个答案:

没有答案