全日历不渲染从戈朗杜松子酒获取的事件



我是golang和web-dev的新手,我使用gin作为api为完整日历提供事件作为json。以下是我的完整日历事件配置:

<script>
$(function(){
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'month',
events: {
url: '/events',
type: 'POST'
}
})
});
</script>

以下是我的杜松子酒处理程序:

func EventsJSON(c *gin.Context) {
start := c.PostForm("start")
end := c.PostForm("end")
es := models.GetEvents(start, end)
jes, err := json.Marshal(es)
if err != nil {
fmt.Println(err)
}
c.JSON(200, gin.H{"events": jes})
}

下面是从 db 和 jes 返回的 []事件:

[{"id":1,"title":"test event",
"start":"2018-10-09T20:07:50.402286+08:00",
"end":"2018-10-09T20:57:50.402286+08:00",
"description":1},
{"id":2,"title":"test event",
"start":"2018-10-11T15:03:43.963198+08:00",
"end":"2018-10-11T15:53:43.963198+08:00",
"description":1}]
[91 123 34 105 100 34 58 49 44 34 116 105 116 108 101 34 58 34 116 101 115 116 32 101 118 101 110 116 34 44 34 115 116 97 114 116 34 58 34 50 48 49 56 45 49 48 45 48 57 84 50 48 58 48 55 58 53 48 46 52 48 50 50 56 54 43 48 56 58 48 48 34 44 34 101 110 100 34 58 34 50 48 49 56 45 49 48 45 48 57 84 50 48 58 53 55 58 53 48 46 52 48 50 50 56 54 43 48 56 58 48 48 34 44 34 100 101 115 99 114 105 112 116 105 111 110 34 58 49 125 44 123 34 105 100 34 58 50 44 34 116 105 116 108 101 34 58 34 116 101 115 116 32 101 118 101 110 116 34 44 34 115 116 97 114 116 34 58 34 50 48 49 56 45 49 48 45 49 49 84 49 53 58 48 51 58 52 51 46 57 54 51 49 57 56 43 48 56 58 4848 34 44 34 101 110 100 34 58 34 50 48 49 56 45 49 48 45 49 49 84 49 53 58 53 51 58 52 51 46 57 54 51 49 57 56 43 48 56 58 48 48 34 44 34 100 101 115 99 114 105 112 116 105 111 110 34 58 49 125 93]

但是事件没有在日历上呈现,我不确定我是否应该在响应客户端之前用 string(jes( 转换它,或者全日历事件配置有问题

我检查了负责人的身体,发现事件是这样的

{"events":"W3siaWQiOjEsInRpdGxlIjoidGVzdCBldmVudCIsInN0YXJ0IjoiMjAxOC0xMC0wOVQyMDowNzo1MC40MDIyODYrMDg6MDAiLCJlbmQiOiIyMDE4LTEwLTA5VDIwOjU3OjUwLjQwMjI4NiswODowMCIsImRlc2NyaXB0aW9uIjoxfSx7ImlkIjoyLCJ0aXRsZSI6InRlc3QgZXZlbnQiLCJzdGFydCI6IjIwMTgtMTAtMTFUMTU6MDM6NDMuOTYzMTk4KzA4OjAwIiwiZW5kIjoiMjAxOC0xMC0xMVQxNTo1Mzo0My45NjMxOTgrMDg6MDAiLCJkZXNjcmlwdGlvbiI6MX1d"}

我做字符串(jes(,响应json变成

{"events":"[{"id":1,"title":"test event","start":"2018-10-09T20:07:50.402286+08:00","end":"2018-10-09T20:57:50.402286+08:00","description":1},{"id":2,"title":"test event","start":"2018-10-11T15:03:43.963198+08:00","end":"2018-10-11T15:53:43.963198+08:00","description":1}]"}

如果我不做 json。元帅((

func EventsJSON(c *gin.Context) {
start := c.PostForm("start")
end := c.PostForm("end")
es := models.GetEvents(start, end)
c.JSON(200, gin.H{"events": es})
}

响应 JSON 变得如下所示,但仍然没有渲染

{"events":[{"id":1,"title":"test event",
"start":"2018-10-09T20:07:50.402286+08:00",
"end":"2018-10-09T20:57:50.402286+08:00","description":1}, 
{"id":2,"title":"test event",
"start":"2018-10-11T15:03:43.963198+08:00",
"end":"2018-10-11T15:53:43.963198+08:00","description":1}]}

事实证明,c.JSON 已经将其序列化为 json,但事件仍然没有呈现到日历中......

它似乎没有提供完整日历可以读取的确切响应格式,因此更改处理程序以不使用键响应可以解决问题

func EventsJSON(c *gin.Context) {
start := c.PostForm("start")
end := c.PostForm("end")
es := models.GetEvents(start, end)
c.JSON(200, es})
}

相关内容

  • 没有找到相关文章

最新更新