1

I have a little web app. And I use a calender(code from here FullCalendar) there inside a .jsp file. I use Spring mvc architecture. So when this page loaded a controller which is responsible for this page loading will add an attribute called calendarEventList to the model. 'calendarEventList' is an ArrayList<calObject>. calObject is a class which contain the details about the even.

I can access those details in the jsp by ${calEvent.eventID} where calEvent is an Object from that ArrayList.

In FullCalendar the event load can be called like below

$('#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. So I want to create the list which I need to give to the fullcalendar. How can I create such a kind of array in JS. It's structure should match [{},{},{},...,{},{}] as given in the example. {} includes a detail about one Object in that calendarEventList ArrayList.

any detailed description will be highly appreciated.

2 Answers 2

1

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;

Try demo

Sign up to request clarification or add additional context in comments.

7 Comments

on demo page click run button, open console and see the result!
The calendarEventList is a Java ArrayList list which contain java Objects. To insert data to the event : I need to populate a [{},{},..,{},{}] like a list. That is what I have to do.I think the format should be match. can you help me with that?
I think your input to the factory function is what I need as my output. [{ item: 1, title: 2, start: 4}, { item: 2, title: 2, start: 4, end: 5}, { item: 3, title: 2, start: 4}]
@prime read stackoverflow.com/questions/15332733/… is about how to convert arraylist to json format
The item, title , start.. are my values of the Object. I can access them like we access any other java Object attributes like, calEvent.item like wise when calEvent is a Object of the ArrayList.
|
0

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. thanks you..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.