asp.net-mvc 如何从 Kendo 网格中的 ClientTemplate 调用 javascript 方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19819127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call javascript method from ClientTemplate in Kendo grid?
提问by Anelook
Is it possible to put in the ClientTemplate of Kendo grid a javascript statement? I would like to calculate some data on the client and then to put the result in the row.
是否可以在 Kendo 网格的 ClientTemplate 中放入 javascript 语句?我想在客户端计算一些数据,然后将结果放在行中。
I tried this:
我试过这个:
columns.Bound("ExecutionStartDateTime").Title("SummaryLine").Width("20%").ClientTemplate("<script> scheduleForm.generateSummary(#= ExecutionStartDateTime #, 2); </script>");
However, it gave no effect.
然而,它没有产生任何效果。
回答by Bishnu Rawal
You can, with template literal syntax:
您可以使用模板文字语法:
<script>
function someFuntion(date) {
var result = "";
// Do whatever you need here (make ajax call etc..) and return result as html string
return result;
}
</script>
And bound your column as:
并将您的列绑定为:
columns.Bound("ExecutionStartDateTime").Title("SummaryLine").Width("20%")
.ClientTemplate("#=someFuntion(ExecutionStartDateTime)#");
// you can even pass 'data' implicit template parameter and extract ExecutionStartDateTime from there
You can even write inline javascript simply using # if(...){# ... #}# syntax. Thisfaq will help you.
您甚至可以简单地使用 # if(...){# ... #}# 语法编写内联 javascript。此常见问题解答将帮助您。

