使用简单的日历脚本,尝试将事件发布到正确的日期;但是jQuery $.extend
没有扩展我的options
对象。以下是HTML文件的摘录:
$("#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"
}]
});
插件的开头:
(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...
我能够访问该对象的属性,但是没有像想象的那样进行扩展。有什么想法吗?
答案 0 :(得分:3)
jQuery.extend
扩展了传入的第一个对象 - 而不是$.extend(defaults, options)
做$.extend({}, defaults, options)
。
答案 1 :(得分:1)
(function($){
$.fn.calendar = function(options){
var defaults= {
month: null,
prev: "prevMonth",
curr: "currMonth",
next: "nextMonth",
events: []
};
options = $.extend(defaults, options);
另外:记住目标是第一个对象......所以在这个例子中,默认值会用选项扩展...