从错误处理程序中获取对剑道格的引用 [英] Get a reference to Kendo Grid from inside the error handler

查看:143
本文介绍了从错误处理程序中获取对剑道格的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有已经是问题,如何让自定义错误处理,具有的答案,但所有这些问题的答案用外部参考/选择到电网,使其工作,例如:

There already are questions how to get custom error handling, with answers, but all those answers use 'external' reference/selector to the grid to make it work, for example:

function onError(e) {
    if (e.errors) {
        var message = "Error:\n";  

        var grid = $('#gridID').data('kendoGrid'); // <<- here
    (...)
}

是否有可能从错误处理功能内获得参考网格无需用手或提供选择'外部'(因为全局变量的 MEH 的)?这样的错误处理脚本可以是完全自包含的。

Is it possible to get the reference to the grid from inside the error handling function without providing the selector by hand or 'externally' (because global variables are meh)? That way the error handling script could be totally self-contained.

推荐答案

显然,源网格现在可以通过 e.sender.table.context.id 检索。谢谢,阿克巴丽

Version 'current' as of 2015-12-05

Apparently, the source grid can now be retrieved via e.sender.table.context.id. Thanks, Akbari!

下面的解决方案将无法正常工作。看来,构件是由数据源丢失。

Solution below won't work. It seems that table member is missing from data source.

我的解决方法是相当粗糙,只是使用选择抓住这回非空的。数据(kendoGrid所有的 K-格元素)和比较数据源arg.sender 。当数据源相匹配 - 我们有这引起了该错误的网格:

My workaround was quite crude, just using selectors to grab all k-grid elements which return not-null for .data("kendoGrid") and compare the data sources with arg.sender. When the data sources match - we have a grid which raised the error:

$(".k-grid").each(function() {
    var grid = $(this).data("kendoGrid");
    if (grid !== null && grid.dataSource == args.sender) {
        // We have a winner!
    }
});


原来的答复

原来 - 上网浏览了好位之后 - 这是可能的。
所以这里有云,任何人在未来某个时候寻找答案,甚至未来的我。


Original answer

Turns out - after browsing the Internet for quite a bit - that it is possible. So here it goes, for anyone searching for the answer sometime in the future, maybe even future-me.

在函数内部,这个未绑定到一格,但到数据源在网格内部使用,所以不能真正被使用的直接的改变错误处理行为。需要的记录不完整神奇一点点。

Inside the function, this is not bound to a grid, but to a DataSource that the grid uses internally, so it can't really be used directly to alter the error-handling behavior. A little bit of poorly documented magic is needed.

这意味着,(作为剑道UI MVC版本2013.3.1119.545)以下,可以用:

It means that (as of Kendo UI MVC version 2013.3.1119.545) the following can be used:

e.sender.options.table.context

返回包装网(DOM元素),而

to return the wrapping grid (DOM element), while

e.sender.options.table.context.id

返回网格的ID。

returns grid's ID.

这意味着,与jQuery,网格可以通过检索

It means that, with jQuery, the grid can be retrieved by:

var grid = $(e.sender.options.table.context).data("kendoGrid");

和错误处理脚本的其余部分仍然是完全一样的。

And the rest of the error-handling script remains exactly the same.

从技术上讲,无论是这个约束的范围和发件人似乎是同样的事情 - 网格的数据源,所以它们应该在上面的例子中可以互换。

Technically, both this bound in the scope and sender seem to be the same thing - grid's DataSource, so they should be interchangeable in the example above.

这篇关于从错误处理程序中获取对剑道格的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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