杰森(Json)事件不起作用,并且工作日不正确 [英] Json event does not work, and the weekday is not right
问题描述
我的日历上有一些有事件的日期.应使用从JSON
调用中接收到的数据突出显示事件的日期.当我单击事件日期时,应显示事件.问题是我的JSON
数据未获取,并且事件未显示.另外,工作日也不对.
On my calendar there are dates that have events. The dates with the events should be highlighted with data received from a JSON
call. When I click on an event date the event should be shown. The problem is my JSON
data is not being fetched and the events don't show. Also, the weekday isn't right.
发出JSON
请求的我的showInfo
代码如下. Codepen 显示了完整的代码示例.
My showInfo
code that makes the JSON
request is below. The Codepen shows the full code example.
// show info
function showInfo(event) {
// link
var url = 'https://codepen.io/nakome/pen/EWBMzm.css';
// get json
getjson(url, function(obj) {
for (var key in obj) {
// if has envent add class
if(_('[data-id="' + key + '"]')){
_('[data-id="' + key + '"]').classList.add('event');
}
if (event === key) {
_('#calendar_data').classList.toggle('show_data');
// template info
var data = '<a href="#" class="hideEvent" '+
'onclick="return hideEvent();">×</a>'+
'<h3>' + obj[key].type + '</h3>' +
'<dl>' +
'<dt><dfn>Title:</dfn></dt><dd>' + obj[key].title + '</dd>' +
'<dt><dfn>Hour:</dfn></dt><dd>' + obj[key].time + '</dd>' +
'<dt><dfn>Venue:</dfn></dt><dd>' + obj[key].venue + '</dd>' +
'<dt><dfn>Location:</dfn></dt><dd>' + obj[key].location + '</dd>' +
'<dt><dfn>Description:</dfn></dt><dd>' + obj[key].desc + '</dd>' +
'<dt><dfn>More Info:</dfn></dt><dd><a href="' + obj[key].more +
'" title="More info">Here</a></dd>' +
'</dl>';
return _('#calendar_data').innerHTML = data;
}
}
});
return false;
}
// toggle event show or hide
function hideEvent(){
_('#calendar_data').classList.toggle('show_data');
}
推荐答案
我认为问题在于,您的showInfo()在calendar()函数开始时已被注释掉.删除评论,这样:
I think the problem is that your showInfo() was commented out at the start of the calendar() function. Remove the comment so this:
// showInfo();
成为这个:
showInfo();
我已经将
I have updated the Codepen for the original question here so you can see that the events are showing up. I'm not sure what you meant by the 'weekday is not right'.
这篇关于杰森(Json)事件不起作用,并且工作日不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!