我编写了我的第一个jquery插件(日历)。现在一切都很好,但是我已经把里面的事件嵌入到我的插件中,比如:
var days = [
new Event('9-5', 'test1', 1),
new Event('9-7', 'test2', 8),
new Event('9-8', 'test3', 2)
];
现在,我将事件“天”从外部提交到我的插件中:
var days = [
['9-5','test1', 1],
['9-7', 'test2', 8],
['9-8', 'test3', 2]
];
$("#cal").calendar( { year: "2015", month: "9", events: days } );
在插件中
var config = {
// default settings
year: "2015",
month: "9",
events: ""
// ...
};
// change default settings
if (settings) { config = $.extend( {}, config, settings ); }
现在,我的问题是用以下方法动态地生成相同的事件数组:
var days = [];
config.events.each(function( index ) {
days.push(new Event(config.events[index][0],config.events[index][1],config.events[index][2]));
});
但我得到了以下错误:
TypeError: config.events.each is not a function
以下是我的活动功能:
function Event(start,title, duration){
if(start instanceof Date){
this.start = start;
}
this.title = title;
this.dur = duration;
this.end= new Date(this.start);
....
}
怎么做才对?非常感谢
编辑
我用了每个功能都不对:
config.events.each(function( index ) {
必须:
$.each(config.events, function( index ) {
发布于 2015-10-02 08:25:31
您没有正确地使用.each。$.each()采用两个参数。第一个是数组/对象,第二个是回调函数。http://api.jquery.com/jquery.each/
https://stackoverflow.com/questions/32902856
复制相似问题