Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 剑道网格获取选定行并分配给局部变量_Angularjs_Typescript_Kendo Grid - Fatal编程技术网

Angularjs 剑道网格获取选定行并分配给局部变量

Angularjs 剑道网格获取选定行并分配给局部变量,angularjs,typescript,kendo-grid,Angularjs,Typescript,Kendo Grid,我正在使用一个剑道网格和AngularJs和TypeScript。我可以获取所选行,但无法将结果分配给局部变量,因为它似乎在不同的范围内运行 “我的网格”具有以下属性: this.gridOptions = { dataSource: { data: this.items, pageSize: 10 }, selectable: 'row', filterable: { mode: 'row' }, change

我正在使用一个剑道网格和AngularJs和TypeScript。我可以获取所选行,但无法将结果分配给局部变量,因为它似乎在不同的范围内运行

“我的网格”具有以下属性:

this.gridOptions = {
    dataSource: {
      data: this.items,
      pageSize: 10
    },
    selectable: 'row',
    filterable: {
      mode: 'row'
    },
    change: this.onItemSelect,
...
}
typescript函数如下所示:

onItemSelect(kendoEvent : any) {
  var grid = kendoEvent.sender;
  this.selectedItem = grid.dataItem(grid.select());
}
selectedItem在我的控制器类中定义:

export class ServicePackageModalController {
private selectedItem : any;
 ...
}
handleNext() {
 console.debug(this.selectedItem) //this is undefined here?
}
问题在于,当我稍后在另一个按钮事件中检查this.selectedItem时,它是未定义的。我假设这是因为在剑道网格中调用函数时作用域不同,所以“this”表示其他内容,而不是我的控制器类:

export class ServicePackageModalController {
private selectedItem : any;
 ...
}
handleNext() {
 console.debug(this.selectedItem) //this is undefined here?
}

所以我的问题是,我如何将此结果分配给我的控制器类,以便以后可以访问它?

解决此问题的唯一方法是将以下代码添加到我的handleNext函数中:

  var entityGrid = $("#EntitesGrid").data("kendoGrid");
  var selectedItem = entityGrid.dataItem(entityGrid.select());

在剑道网格指令中,您还需要有一个名为
EntitiesGrid
id
属性。

这个属性只返回最新选定的行,如何获得整个选定行?