如何从 Angular 控制器调用剑道网格上的 refresh()? [英] How to call refresh() on a kendo-grid from an Angular controller?

查看:19
本文介绍了如何从 Angular 控制器调用剑道网格上的 refresh()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循一些有关刷新剑道网格的建议,例如 this.

最重要的是,在我的 html 中:

然后在控制器中我有:

vm.webapiGrid.refresh();

注意:我使用的是 ControllerAs 语法,所以我使用的是vm"而不是 $scope.

我的问题是vm.webapiGrid"未定义.这看起来很简单,但我不知道为什么它是未定义的.

解决方案

找到了答案.刷新我读到的数据源的另一种方法是执行以下操作:

vm.mainGridOptions.datasource.transport.read();

这对我不起作用,因为读取"未定义.查看我的数据源定义,我看到了原因,read 需要一个参数(在本例中为e"):

 vm.mainGridOptions = {数据源: {运输: {阅读:功能(e){task.getAllTask​​s(vm.appContext.current.contextSetting).然后(功能(数据){e.成功(数据);});},}},

为了解决,我将e"保存在我的范围中,然后在我想刷新时重新使用它:

 vm.mainGridOptions = {数据源: {运输: {阅读:功能(e){task.getAllTask​​s(vm.appContext.current.contextSetting).然后(功能(数据){e.成功(数据);vm.optionCallback = e;});},}},

然后:

if (vm.optionCallback !== undefined) {vm.mainGridOptions.dataSource.transport.read(vm.optionCallback);}

问题已解决(希望如此).

I'm attempting to follow several suggestions on refreshing a kendo-grid such as this.

The essential is that in the html I have:

<div kendo-grid="vm.webapiGrid" options="vm.mainGridOptions">

Then in the controller I have:

vm.webapiGrid.refresh();

Note: I'm using the ControllerAs syntax so I am using "vm" rather than $scope.

My problem is that "vm.webapiGrid" is undefined. This seems so straightforward, but I'm not sure why it is undefined.

解决方案

Found the answer. One other method of refreshing the datasource I read about was to do something like:

vm.mainGridOptions.datasource.transport.read();

This wasn't working for me as "read" was undefined. Looking at my datasource definition, I saw the reason, read needs a parameter (in this case "e"):

    vm.mainGridOptions = {
        dataSource: {
            transport: {
                read: function (e) {
                    task.getAllTasks(vm.appContext.current.contextSetting).
                        then(function (data) {
                            e.success(data);
                        });
                },
            }
        },

To solve, I saved "e" in my scope and then reused it when I wanted to refresh:

    vm.mainGridOptions = {
        dataSource: {
            transport: {
                read: function (e) {
                    task.getAllTasks(vm.appContext.current.contextSetting).
                        then(function (data) {
                            e.success(data);
                            vm.optionCallback = e;
                        });
                },
            }
        },

and then:

if (vm.optionCallback !== undefined) {
   vm.mainGridOptions.dataSource.transport.read(vm.optionCallback);
}

Problem solved (I hope).

这篇关于如何从 Angular 控制器调用剑道网格上的 refresh()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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