0

I'm using responsive calendar in a mvc project. When setting up the calendar, I need to fill an object called events with my data.

$(".responsive-calendar").responsiveCalendar({
            time: '@DateTime.Now.Year.ToString()' + '-' + '@DateTime.Now.Month.ToString()',
            events: { //object to fill with my model data
            "2013-04-30": { "number": 5, "url": "http://w3widgets.com/responsive-slider" },
            "2013-04-26": { "number": 1, "url": "http://w3widgets.com" },
            "2013-05-03": { "number": 1 },
            "2013-06-12": {},
            "2015-06-12": { "number": 1 }
       }
  });

However this object isn't an array. How to achieve this

Update : My model is a list of DateEvents :

class DateEvents 
{ 
    DateTime Date {get;set;} 
    int Count {get;set;}
}
5
  • What structure would you like the array to have? Commented Jun 21, 2016 at 10:09
  • You can add key and value in Object.. What is the question ? Commented Jun 21, 2016 at 10:09
  • I suggest you to add some information about your model data to your question. Commented Jun 21, 2016 at 10:11
  • 1
    You can do events[key] = value. Commented Jun 21, 2016 at 10:12
  • have you tried adding [] in your code? That's how you make a array Commented Jun 21, 2016 at 10:13

1 Answer 1

1

When you have an array with data, but must supply it like in your example in the 'events' property, you can create an object like below.

var myEvents = {};
myEvents["2013-04-30"] = { "number": 5, "url": "http://w3widgets.com/responsive-slider" };

If you can do this for one item, you can do this also in a loop (forEach) to get the data from an existing source (array?) and add it to the myEvents object. After completion of 'myEvents', you can set the value of 'events' of the responsiveCalendar to 'myEvents'.

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

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.