Jquery完整日历问题 - 关于事件组和多个事件源的颜色

cho*_*bo2 4 jquery jquery-plugins fullcalendar

我正在看jquery完整的日历1.5,并有几个问题.

多源如何?

jQuery $.ajax options

You can also specify any of the jQuery $.ajax options within the same object! This allows you to easily pass additional parameters to your feed script, as well as listen to ajax callbacks:

    $('#calendar').fullCalendar({

        eventSources: [

            // your event source
            {
                url: '/myfeed.php',
                type: 'POST',
                data: {
                    custom_param1: 'something',
                    custom_param2: 'somethingelse'
                }
                error: function() {
                    alert('there was an error while fetching events!');
                },
                color: 'yellow',   // a non-ajax option
                textColor: 'black' // a non-ajax option
            }

            // any other sources...

        ]

    });
Run Code Online (Sandbox Code Playgroud)

来自:http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/

你会用逗号然后复制第一个吗?

我的第二个问题是.我将有一个事件源(因为它们都来自同一个源)但我会在那里有一组事件,每个组需要不同的颜色.

所以我可以拥有这个

Item 1 - group 1 (color red)
Item 2 - group 1 (color red)
Item 3 - group 2  (color green)
Item 4 - group 3 (color black)
Run Code Online (Sandbox Code Playgroud)

现在这些颜色是由用户设置的,所以我永远不会知道一个颜色组.一个用户可能将其设置为红色,可能将其设置为蓝色.

所以我认为我需要为每个事件发送颜色.因此,第1项将具有与之关联的颜色,而第2项将具有关联的颜色等.

怎么会这样?我想,一旦我把事件发回来,我需要做点什么.我只是不确定是什么.

谢谢

Mil*_*ric 11

要处理多个源,你是对的,只需在eventSources数组中添加更多:

$('#calendar').fullCalendar({

    eventSources: [

        // your event source
        {
            url: '/myfeed.php',
            type: 'POST',
            data: {
                custom_param1: 'something',
                custom_param2: 'somethingelse'
            }
            error: function() {
                alert('there was an error while fetching events!');
            },
            color: 'yellow',   // a non-ajax option
            textColor: 'black' // a non-ajax option
        },

        // your second event source
        {
            url: '/myfeed.php',
            type: 'POST',
            data: {
                custom_param3: 'somethingelseelse',
                custom_param4: 'somethingelseelseelse'
            }
            error: function() {
                alert('there was an error while fetching events!');
            },
            color: 'red',   // a non-ajax option
            textColor: 'white' // a non-ajax option
        }

        // any other sources...

    ]

});
Run Code Online (Sandbox Code Playgroud)

对于多个组的不同颜色,fullCalendar仅允许每个事件源使用一种颜色.因此,您必须为每个组添加一个源到eventSource.至于让用户自定义颜色,使用上面的例子,你可以这样:

$('#calendar').fullCalendar({

    eventSources: [

        // your event source
        {
            url: '/myfeed.php',
            type: 'POST',
            data: {
                custom_param1: 'something',
                custom_param2: 'somethingelse'
            }
            error: function() {
                alert('there was an error while fetching events!');
            },
            color: settings.customBackgroundColors(userId, groupX),   // a non-ajax option
            textColor: settings.customTextColors(userId, groupX) // a non-ajax option
        },

        // your second event source
        {
            url: '/myfeed.php',
            type: 'POST',
            data: {
                custom_param3: 'somethingelseelse',
                custom_param4: 'somethingelseelseelse'
            }
            error: function() {
                alert('there was an error while fetching events!');
            },
            color: settings.customBackgroundColors(userId, groupY),   // a non-ajax option
            textColor: settings.customTextColors(userId, groupY) // a non-ajax option
        }

        // any other sources...

    ]

});
Run Code Online (Sandbox Code Playgroud)


编辑

如果你想从json feed中获得每个事件的单独属性,就像个别颜色一样.

public int id { get; set; }
public string title { get; set; }
public bool allDay { get; set; }
public string start { get; set; }
public string end { get; set; }
public string color { get; set; }
public string textColor { get; set; }
Run Code Online (Sandbox Code Playgroud)

用你想要的颜色填充字符串,然后将每个事件的内容集合起来,然后将其发送回json结果,每个任务都应该使用你在color属性中设置的任何内容.