[英]How to create a customized javaScript array?
I have a little web app. 我有一个小的网络应用程序。 And I use a calender(code from here FullCalendar ) there inside a .jsp file.
我在.jsp文件中使用了压延机(来自这里的代码FullCalendar )。 I use Spring mvc architecture.
我使用Spring MVC架构。 So when this page loaded a controller which is responsible for this page loading will add an attribute called
calendarEventList
to the model
. 所以,当这个页面加载控制器,负责此页面加载会添加称为属性
calendarEventList
的model
。 'calendarEventList' is an ArrayList<calObject>
. 'calendarEventList'是一个
ArrayList<calObject>
。 calObject is a class which contain the details about the even. calObject是一个类,其中包含有关偶数的详细信息。
I can access those details in the jsp by ${calEvent.eventID}
where calEvent
is an Object from that ArrayList. 我可以通过
${calEvent.eventID}
访问jsp中的那些详细信息,其中calEvent
是该ArrayList中的一个对象。
In FullCalendar the event load can be called like below 在FullCalendar中,事件加载可以如下所示
$('#calendar').fullCalendar({
events: [
{
title : 'event1',
start : '2010-01-01'
},
{
title : 'event2',
start : '2010-01-05',
end : '2010-01-07'
},
{
title : 'event3',
start : '2010-01-09 12:30:00',
allDay : false // will make the time show
}
]
});
I want is like below 我想要像下面
$('#calendar').fullCalendar({
events: //read the `calendarEventList` and create a suitable array
});
I have title
, start
, end
.. details in a Oblect of the calendarEventList
. 我
Oblect of the calendarEventList
的Oblect of the calendarEventList
具有title
, start
, end
..详细信息。 So I want to create the list which I need to give to the fullcalendar
. 所以我想创建一个列表,我需要提供给全
fullcalendar
。 How can I create such a kind of array in JS. 如何在JS中创建这种数组。 It's structure should match
[{},{},{},...,{},{}]
as given in the example. 如
[{},{},{},...,{},{}]
其结构应与[{},{},{},...,{},{}]
匹配。 {}
includes a detail about one Object in that calendarEventList
ArrayList. {}
包含有关该calendarEventList
ArrayList中的一个对象的详细信息。
any detailed description will be highly appreciated. 任何详细的描述将是高度赞赏的。
If i truly understand your question ( you have array of objects, all objects contains different field, but each object contains title, start (and end)). 如果我真正理解您的问题(您有对象数组,则所有对象都包含不同的字段,但是每个对象都包含标题,开始(和结束))。 So your task is filter this array.
因此,您的任务是过滤该数组。
Solution: 解:
function factory(array){
return array.map(function(item){
var instance = {title: item.title, start: item.start};
if(item.end) instance.end = item.end;
return item;
});
}
var res = factory([{ item: 1, title: 2, start: 4, an: 123, pp: "asdf"}, { item: 2, title: 2, start: 4, end: 5}, { item: 3, title: 2, start: 4}]);
Output will be filtered array of objects with start, title, (end) fields; 输出将被过滤后的对象数组,其中包含开始,标题,(结束)字段;
Let try with my example: 让我们尝试以下示例:
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var employees = [];
employees.push({ id: 111, title: "Testing Event 001", start: new Date(y, m, d-5,10,30) , end: new Date(y, m, d-5,12,30),className: ['yellow-event', 'black-text-event']});
employees.push({ id: 111, title: "Testing Event 002", start: new Date(y, m, d-3,10,30) , end: new Date(y, m, d-3,12,30),className: ['yellow-event', 'black-text-event']});
on events: employees
put like this,, Hope it help full. 关于
events: employees
们这样说,希望它能对大家有所帮助。 thanks you.. 谢谢..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.