如何从SignalR集线器方法更新Kendo调度程序?

时间:2014-02-04 02:46:45

标签: javascript kendo-ui signalr kendo-scheduler

这是使用signalr的代码,它成功地将信息发送到集线器,集线器正在做一个clients.all.Notifiy等等......我只是添加你推荐的代码示例,我从scheduler_change(e)执行此操作,以便一次单击它将插入从集线器返回的信息..由于某种原因,新预订不会显示在调度程序上。

 function scheduler_change(e) {
        var start = e.start; //selection start date
        var end = e.end; //selection end date
        var slots = e.slots; //list of selected slots
        var events = e.events; //list of selected Scheduler events


        var notificationHub = $.connection.MyBookingHub;
        notificationHub.client.Notify = function (MyStart, MyEnd, MyMessage) {

       //     kendoConsole.log(kendo.toString(new Date(MyStart) + " " + new Date(MyEnd) + " " + MyMessage));


            var scheduler = $("#scheduler").data("kendoScheduler", function () {
                scheduler.dataSource.add({
                    start: new Date(MyStart),
                    end: new Date(MyEnd),
                    title: "Costas Interview"
                });
           });

        };


        $.connection.hub.start().done(function () {

            notificationHub.server.sendNotification(start, end, "Booking Title");

        });
    }

1 个答案:

答案 0 :(得分:0)

您应该只创建一次client.notify方法,而不是每次触发调度程序窗口小部件上的更改事件时。同样可以开始连接。

所以它可能应该是这样的:

// set up hub methods and start connection ..
var notificationHub = $.connection.MyBookingHub;
notificationHub.client.Notify = function (MyStart, MyEnd, MyMessage) {
    var scheduler = $("#scheduler").data("kendoScheduler");
    scheduler.dataSource.add({
        start: new Date(MyStart),
        end: new Date(MyEnd),
        title: "Costas Interview"
    });
};

window.hubConnection = $.connection.hub.start();

// create scheduler change handler
function scheduler_change(e) {
    var start = e.start; //selection start date
    var end = e.end; //selection end date
    var slots = e.slots; //list of selected slots
    var events = e.events; //list of selected Scheduler events

    window.hubConnection.done(function () {
        notificationHub.server.sendNotification(start, end, "Booking Title");
    });
}