javascript - 显示某些事件,但某些事件不在 FullCalendar 中
问题描述
我在尝试在 FullCalendar 上显示事件时遇到问题。有些事件会显示,有些则不会。
我通过JSON填充 FC ,到目前为止,即使分页仅检索所选月份的事件,它也能正常工作。
...
events: {
url: '/getEvents',
method: 'GET',
failure: function(error) {
console.log(error);
alerta("Error", "Ups...", "red");
},
},
...
但是现在我正在尝试从存储在数据库中的其他内容中添加更多事件,尽管以相同的方式构建它们,但它们并未显示在日历上。
我构建这样的事件(我已经清理了代码):
rows = connection.execute("SELECT...........")
events = []
for row in rows:
event = {"id": row['id'], "title": row['title'], "start": row['start'], "end": row['end'], "allDay": row['allDay'], "url": row['url'], "color": row['color'], "extendedProps": {"company": row['company'], "state": fila['state']}}
if row['groupId'] is not None:
event['groupId'] = str(row['groupId'])
events.append(event)
现在,在程序的其他部分,我以类似的方式创建事件:
more_rows = connection.execute("SELECT....")
more_events = []
for row in more_rows:
event = {"id": row['id'], "title": row['title'], "start": row['start'], "end": row['end'], "allDay": 1, "url": "", "color": row['color'], "extendedProps": {"company": row['company'], "description": row['description'], "type": row['type'], "tecnology": row['tecnology'], "state": row['state']}}
more_events.append(event)
它们一起发送到浏览器:
...
events.extend(more_events)
return jsonify(events), 200
...
将jsonify(events)
这个 JSON 发送到浏览器(我在 python 代码上使用双引号,但 jsonify 将其替换为单引号):
[{'allDay': 1, 'color': 'blue', 'end': '2019-10-24T00:00:00.000Z', 'extendedProps': {'company': 'Company test', 'state': 'Active'}, 'groupId': '48', 'id': 27, 'start': '2019-10-23T00:00:00.000Z', 'title': 'A title', 'url': ''},
{'allDay': 1, 'color': 'blue', 'end': '2019-10-11T00:00:00.00.000Z', 'extendedProps': {'company': 'Company test', 'description': 'oapisdvañklsjdhalksjdflaksjdf', 'state': 'Active', 'tecnology': 'javascript+html', 'type': 'Cool'}, 'id': 74, 'start': '2019-10-07T00:00:00.00.000Z', 'title': 'owqsakjdflh', 'url': ''},
{'allDay': 1, 'color': 'blue', 'end': '2019-10-23T00:00:00.00.000Z', 'extendedProps': {'company': 'Company test', 'description': 'sdgsdfgwertwertwg', 'state': 'Active', 'tecnology': 'c', 'type': 'Cool'}, 'id': 75, 'start': '2019-10-21T00:00:00.00.000Z', 'title': '1eqwrwqer', 'url': ''},
{'allDay': 1, 'color': 'blue', 'end': '2019-11-07T00:00:00.00.000Z', 'extendedProps': {'company': 'Company test', 'description': 'asdfafasdfasdfasdf', 'state': 'Active', 'tecnology': 'java', 'type': 'Cool'}, 'id': 76, 'start': '2019-11-04T00:00:00.00.000Z', 'title': 'Bla bla bla', 'url': ''}]
问题是......它作为事件打印的第一个元素,但 JSON 上的其余元素没有打印。
我看不出我的错误在哪里或我做错了什么。
问候。
解决方案
我发现了问题(嗯,实际上是一个同事),它就在这里:
第一个元素:'end':'2019-10-24T00:00:00.000Z'
||'start':'2019-10-23T00:00:00.000Z'
其他元素:'end': '2019-10-23T00:00:00.00.000Z'
||'start': '2019-10-21T00:00:00.00.000Z'
事情是:2019-10-24T 00:00:00 .000Z 和 2019-10-23T 00:00:00.00 .000Z
我使用这个 SQL 来比较日期(它们没有存储在 ISO 8601 中):
SELECT id, ....., strftime('%Y-%m-%dT%H:%M:%fZ', start_date) AS start, strftime('%Y-%m-%dT%H:%M:%fZ', end_date) AS end, ......
FROM table
WHERE state = 'Active' AND start > '....' AND end < '....'
我的问题是假设SQlite strftime它等于PYTHON strftime,但不是。
我使用的是这个(Python):'%Y-%m-%dT%H:%M: %S.%f Z'而不是这个(SQlite):'%Y-%m-%dT%H:% M: %f Z'
%S Second as a zero-padded decimal number.
%f Microsecond as a decimal number, zero-padded on the left.
%S seconds: 00-59
%f fractional seconds: SS.SSS
所以要小心,不要将 python 格式与 sqlite 格式混淆。
问候!
推荐阅读
- javascript - onAuthStateChange 中的 setState 不起作用
- reactjs - 反应部署问题
- android - 安卓。文本视图。文本的最后一个可见字符
- php - 在 html img 标签中加入 php
- python - 无法将符号张量 (sequential_34/sequential_33/random_rotation_8/rotation_matrix/strided_slice:0) 转换为 numpy 数组
- javascript - 如何在反应选择中使用 onChange
- combobox - WPF修改的组合框选择不起作用
- android - 如何在颤动中维护页面的状态
- go - 尝试在测试模式下在 VSCode 调试器上调试 golang 时出现奇怪的错误
- python - 我如何向不和谐请求添加附件?