我在尝试在 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'
|| '开始':'2019-10-23T00:00:00.000Z'
其他元素:'end': '2019-10-23T00:00:00.00.000Z'
|| '开始':'2019-10-21T00:00:00.00.000Z'
事情是:2019-10-24T00:00:00.000Z 和 2019-10-23T00: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.%fZ'而不是这个(SQlite):'%Y -%m-%dT%H:%M:%fZ'
%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 - 某些事件会显示,但另一些事件不会显示在 FullCalendar 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58223296/