剑道网格:在角指令得到一个实例 [英] Kendo Grid: getting an instance in a Angular directive
问题描述
这直接如下从<一个href=\"http://stackoverflow.com/questions/28447578/kendo-grid-getting-widget-instance-in-angular\">this问题(带有一个额外的问题,所以我认为应该是一个新的职位?)
this follows directly on from this question (with an additional question hence I thought should be a new post?)
上面的链接显示了如何在角获得一格的实例(感谢拉尔斯)
The link above shows how to get a grid instance in Angular (thanks to Lars)
所以,从这个最后的例子下面,我现在已经添加了下面的指令。
So, following on from this last example, I now have added the following directive..
<body>
<div data-ng-app="app">
<div data-ng-controller="Grid as vm">
<div id='aa'>
<div pckendo id='bb' kendo-grid='grid'
k-options="vm.options"></div>
</div>
</div>
</div>
</body>
和中添加的.js文件
angular
.module("app", ["kendo.directives"])
.controller("Grid", Grid)
.directive('pckendo', PCKendo);
....
function PCKendo() {
function link(scope, element, attrs) {
var instance = element;
var vm = scope.vm;
vm.msg = "";
var grid = scope.grid;
}
return {
link: link
}
请参阅这里完整的例子。
而不是在控制器获取实例,我想通过指令得到它(从我的理解这是一个更好的地方做事件处理等)
Rather than getting the instance in the controller, I would like to get it via a directive (as from what I understand this is a better place to do event handling etc)
我试图在那里的几件事情,但一直没能得到电网实例,因此这里的任何进一步的帮助将是巨大的。
I have tried a few things in there, but haven't been able to get the grid instance, so any further help here would be great.
在此先感谢!
推荐答案
基本上你做同样的事情;你需要等待 kendoRendered
事件,例如像这样(注意这个例子可能不符合角度的最佳实践(再分离范围等)):
Basically you do the same thing; you need to wait for the kendoRendered
event, e.g. like this (note that this example may not conform to angular best practices (re isolate scope etc.)):
function PCKendo($timeout) {
function link(scope, element, attrs) {
scope.$on("kendoRendered", function (e) {
scope.$apply(function () {
scope.vm.setMessage("one col");
scope.grid.hideColumn(1);
});
$timeout(function () {
scope.$apply(function () {
scope.vm.setMessage("all cols");
scope.grid.showColumn(1);
});
}, 2000);
});
}
return {
link: link
}
}
(演示)
这篇关于剑道网格:在角指令得到一个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!