【问题标题】:Jaydata as KendoDataSource doesn't automatically refresh on new record addJaydata 作为 KendoDataSource 不会在新记录添加时自动刷新
【发布时间】:2015-04-19 09:46:52
【问题描述】:

我正在使用 jaydata 来管理仅限客户端的数据存储。数据通过 SignalR 广播接收。接收到的数据缓存在内存中。内存缓冲区每秒刷新一次到 jaydata 存储并保存。

绑定到 jaydata 存储的 Kendo Grid 不会自动更新。一旦 jaydata saveChanges 方法完成,我需要在 dataSource 上调用 read 方法。下面的代码是定时器触发时调用的方法。

$scope.updateGrid = function () {
    if ($scope.allowUpdate) {
        var data = $scope.scribeMessages.splice(0, $scope.scribeMessages.length);
        if (data.length > 0) {
            scribeDb.Messages.addMany(data);
            scribeDb.saveChanges().then(function () { $scope.scribeGrid.dataSource.read(); });
        }
    }
};

在我的 Kendo Grid 中,我将 dataSource 定义如下:

    dataSource: scribeDb.Messages.asKendoDataSource({
        pageSize: 20,
        sort: [{ field: "SequenceId", dir: "desc" }]
    })

我已经定义了实体、实体集和被划为:

$data.Entity.extend("ScribeMessage", {
    SequenceId: { type: "string", required: true, key: true, computed: false },
    ScribeId: { type: "string", required: true },
    Environment: { type: "string", required: true },
    LogLevel: { type: "integer", required: true },
    Program: { type: "string", required: true },
    Subject: { type: "string", required: false },
    Message: { type: "string", required: false },
    MachineName: { type: "string", required: true },
    InstanceId: { type: "string", required: false },
    ComponentId: { type: "string", required: false },
    Exception: { type: "string", reguired: false },
    ServerTime: { type: "date", required: true },
    ClientTime: { type: "date", required: true },
    User: { type: "string", required: true }
});

$data.EntityContext.extend("ScribeDatabase", {
    Messages: { type: $data.EntitySet, elementType: ScribeMessage }
});

var scribeDb = new ScribeDatabase({ provider: "indexedDb", databaseName: "ScribeMessages" });

我期待网格绑定数据源自动检测底层数据存储已更改。

是否需要强制读取数据源?

提前感谢您的帮助。

【问题讨论】:

    标签: kendo-ui kendo-grid jaydata


    【解决方案1】:

    预计不会检测到更改。这与将网格连接到服务器的行为相同,您不会收到更改通知。你要么有内置的投票,要么有自己的推送通知。

    JayData 确实提供了您可以挂钩的数据更改时的事件,例如我经常使用

    context.Dogs.addEventListener('afterUpdate', function(){ alert('doggy updated'); });

    如果您可以告诉网格的数据源重新加载。但是请确保用户当前没有在编辑某些内容……我相信这就是 JayData 不强制重新加载的原因,因为他们无法确定用户是否正在对网格执行某些操作。

    玩得开心,JayData 和 Kendo 的婚姻有点不稳定。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      • 2015-05-23
      相关资源
      最近更新 更多