Reputation: 3224
Working on a simple calendar script, trying to make it possible for events to be posted to the proper day; however the jQuery $.extend
is not extending my options
object. Here is the snippet from the HTML file:
$("#cal").calendar({
month: 2,
events: [{
date: "2013-4-10",
workorder: 1234567890,
district: 01,
range: "2:00pm - 4:00pm",
appNotes: "This is just a sample of some notes... end",
installer: "John Doe",
cityNotes: "This is just another sample of some notes... end"
}, {
date: "2013-4-1",
workorder: 1234567890,
district: 01,
range: "3:00pm - 5:00pm",
appNotes: "This is just a sample of some notes... end",
installer: "John Doe",
cityNotes: "This is just another sample of some notes... end"
}]
});
And the beginning of my plug in:
(function($){
$.fn.calendar = function(options){
var defaults= {
month: null,
prev: "prevMonth",
curr: "currMonth",
next: "nextMonth",
events: []
}, options = $.extend(defaults, options);
return($(this).each(function(){
var obj = $(this),
// Etc...
I'm able to access properties of the object, however it is not being extended as thought. Any ideas?
Upvotes: 2
Views: 7945
Reputation: 1916
(function($){
$.fn.calendar = function(options){
var defaults= {
month: null,
prev: "prevMonth",
curr: "currMonth",
next: "nextMonth",
events: []
};
options = $.extend(defaults, options);
Also: remember that the Target is the first object... so in this example, defaults would have been extended with options...
Upvotes: 1
Reputation: 159885
jQuery.extend
extends the first object passed in - rather than doing $.extend(defaults, options)
do $.extend({}, defaults, options)
.
Upvotes: 4