如何从 SignalR 集线器方法更新 Kendo 调度程序? [英] How do I update a Kendo scheduler from a SignalR hub method?

查看:19
本文介绍了如何从 SignalR 集线器方法更新 Kendo 调度程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Here is the code using signalr, it successfully sends the information to the hub and the hub is just doing a clients.all.Notifiy etc etc..... I've just add the code sample that you recommedend, i doing this from the scheduler_change(e) so that on a single click it will insert the info that is returned from the hub.. for some reason the new booking does not show on the scheduler.

 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");

        });
    }

推荐答案

您应该只创建一次 client.notify 方法,而不是每次触发调度程序小部件上的更改事件时.启动连接也是如此.

You should only create the client.notify method once, not each time the change event on the scheduler widget is triggered. Same goes for starting the connection.

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

So it should probably be something like:

// 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");
    });
}

这篇关于如何从 SignalR 集线器方法更新 Kendo 调度程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆