【发布时间】:2016-07-19 15:49:27
【问题描述】:
在我的html模板中
<div kendo-grid="vm.myGrid" k-options="vm.defaultGridOptions" />
在相关的组件类(实现ng.IComponentOptions)中我指定了
this.controllerAs = 'vm';
在控制器代码中
class MyController{
...
static $inject = ['$log', '$scope']
constructor(protected $log: ng.ILogService,
protected $scope: ng.IScope){
this.defaultDataSource = new kendo.data.DataSource(<kendo.data.DataSourceOptions>{ ...}
this.defaultGridOptions = {
dataSource: this.defaultDataSource,
columns: [
{
field: 'someField',
title: 'Some field',
width: 50
},
{
command: [{
template: '<span class="k-button" ng-click="vm.onSomeEvent($event)"> Click Here</span>'
}],
width: 60
}
}
在 onSomeEvent 方法中,我想使用类似这样的方法检索所选项目
private onSomeEvent($event): void{
var grid = $(this).data("kendoGrid");//well, I tried some other approaches too
var selectedItem = grid.dataItem(grid.select());
//use the selectedItem
}
这不起作用,因为“网格”未定义。这提出了两个问题:
如何正确引用 myGrid?
考虑到我可以同时访问 defaultGridOptions 和 defaultDataSource,是否有更好的方法来获取所选项目?
也许是一个微不足道的问题,但我是 angular/typescript/kendo 的新手,我已经花了一些不平凡的时间。谢谢
【问题讨论】:
标签: javascript angularjs typescript kendo-ui controller