[英]getting the event from variable
im studing the jquery calendar from github: https://github.com/themouette/jquery-week-calendar 我从github学习jquery日历: https : //github.com/themouette/jquery-week-calendar
I pull the data from database by using code behind C#, and stored it at hiddenfield, then javascript read the hiddenfield field value as string. 我使用C#背后的代码从数据库中提取数据,并将其存储在hiddenfield中,然后javascript以字符串形式读取了hiddenfield字段值。
i will skip how i get the value from database, in this question, i hardcode the events into sampleEvents var. 我将跳过如何从数据库中获取值,在这个问题中,我将事件硬编码为sampleEvents var。
Working Javascript: 工作的Javascript:
var eventData = {
events: [
{'id':1, 'start': new Date(2015, 3, 27, 12), 'end': new Date(2015, 3, 27, 13, 35),'title':'Lunch with Mike'},
{'id':2, 'start': new Date(2015, 3, 28, 10), 'end': new Date(2015, 3, 28, 14, 45),'title':'Dev Meeting'}
]};
Not Working Javascript: 无法使用Javascript:
var sampleEvents = "{'id':1, 'start': new Date(2015, 3, 27, 12), 'end': new Date(2015, 3, 27, 13, 35),'title':'Lunch with Mike'},{'id':2, 'start': new Date(2015, 3, 28, 10), 'end': new Date(2015, 3, 28, 14, 45),'title':'Dev Meeting'}";
var eventData = {
events: [
sampleEvents
]};
Error message: 错误信息:
Uncaught TypeError: Cannot read property 'getTime' of undefined
Not Working Javascript 2: 无法使用Javascript 2:
var sampleEvents = "[{'id': 1,'start': new Date(2015, 3, 27, 12),'end': new Date(2015, 3, 27, 13, 35),'title': 'Lunch with Mike'},{'id': 2,'start': new Date(2015, 3, 28, 10),'end': new Date(2015, 3, 28, 14, 45),'title': 'Dev Meeting'}]";
var array = JSON.parse(sampleEvents);
var eventData = {
events:
sampleEvents
};
Error Messsage: 错误消息:
Uncaught SyntaxError: Unexpected token '
Can anyone tell me, what did i missed? 谁能告诉我,我错过了什么?
Because your created sampleEvents
is string not array. 因为您创建的
sampleEvents
是字符串而不是数组。
event
is accepting array
not a string
. event
接受array
而不是string
。
To use array try this: 要使用数组,请尝试以下操作:
var sampleEvents = [
{
'id':1,
'start': new Date(2015, 3, 27, 12),
'end': new Date(2015, 3, 27, 13, 35),
'title':'Lunch with Mike'
},
{
'id':2,
'start': new Date(2015, 3, 28, 10),
'end': new Date(2015, 3, 28, 14, 45),
'title':'Dev Meeting'
}
];
To Use String try this: 要使用字符串,请尝试以下操作:
var sampleEvents = '['+
'{"id":1, "start": "'+new Date(2015, 3, 27, 12)+'", "end": "'+new Date(2015, 3, 27, 13, 35)+'","title":"Lunch with Mike"},'+
'{"id":2, "start": "'+new Date(2015, 3, 28, 10)+'", "end": "'+new Date(2015, 3, 28, 14, 45)+'","title":"Dev Meeting"}'+
']';
var sampleEventsArray = JSON.parse(sampleEvents);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.