如何解决以json
我正在尝试为日历添加一个端点,以用于添加事件。
我想尝试使用json
并进行构建,然后解析为日历视图。
然后尝试通过合并json
数据来尝试添加事件,如下所示:
在这一点上,我正在努力将其他数据放入端点。这是我到目前为止所拥有的:
// build variables
$getStart = '2020-01-01'; // come from $_GET
$monthStartDate = new DateTime( $getStart );
$monthFinishDate = clone $monthStartDate;
$monthFinishDate->modify('last day of december');
$monthInterval = new DateInterval( 'P1M' );
// set the variables
$monthRange = new DatePeriod(
$monthStartDate,$monthInterval,$monthFinishDate
);
// loop the months
foreach ($monthRange as $month) {
// loop the days
$dayStartDate = new DateTime( $month->format('M') );
$dayFinishDate = clone $dayStartDate;
$dayFinishDate->modify('next month');
$dayInterval = new DateInterval( 'P1D' );
$dayRange = new DatePeriod(
$dayStartDate,$dayInterval,$dayFinishDate
);
// build the calendar json
$calendar[] = [ $month->format('m') => [
'year' => $month->format('Y'),'month' => $month->format('F'),'days' => [
// error here because loop in $array
foreach( $dayRange as $day ) {
$day->format('d') => [
'dayOfWeek' => $day->format('l'),'events' => []
],}
],]];
}
// print it
echo json_encode($calendar);
我相当确定是因为箭头内的循环,但是我想不出任何其他方法来获取该月的天数。
解决方法
您首先需要构建days数组,所以foreach将创建一个days数组,然后将完成的数组添加到日历中...
# basic_detail.js
...
<div className="">
<label htmlFor="lastName">Profile Summary</label>
<EditorContainer onChnage ={hangleEditorChange}/>
</div>
...
```js
# text_editor.js
onEditorStateChange = (editorState) => {
this.setState({
editorState
});
this.props.onChange(editorState)
};
,
实际上,您不能在数组内使用foreach。在这里,您可以使用函数来做到这一点:
function dayRangeLoop($dayRange) {
$result = [];
foreach( $dayRange as $day ) {
$result[$day->format('d')] = [
'dayOfWeek' => $day->format('l'),'events' => []
];
}
return $result;
}
,然后在您的日历版本中调用它:
// build the calendar json
$calendar[] = [ $month->format('m') => [
'year' => $month->format('Y'),'month' => $month->format('F'),'days' => dayRangeLoop($dayRange)
]];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。