如何在 Kendo 网格中从 ClientTemplate 调用 javascript 方法? [英] How to call javascript method from ClientTemplate in Kendo grid?
本文介绍了如何在 Kendo 网格中从 ClientTemplate 调用 javascript 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 Kendo 网格的 ClientTemplate 中放入 javascript 语句?我想在客户端计算一些数据,然后将结果放在行中.
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.
我试过了:
columns.Bound("ExecutionStartDateTime").Title("SummaryLine").Width("20%").ClientTemplate("<script> scheduleForm.generateSummary(#= ExecutionStartDateTime #, 2); </script>");
然而,它没有任何作用.
However, it gave no effect.
推荐答案
你可以,使用模板文字语法:
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>
并将您的列绑定为:
columns.Bound("ExecutionStartDateTime").Title("SummaryLine").Width("20%")
.ClientTemplate("#=someFuntion(ExecutionStartDateTime)#");
// you can even pass 'data' implicit template parameter and extract ExecutionStartDateTime from there
您甚至可以简单地使用 # if(...){# ... #}# 语法编写内联 JavaScript.此常见问题解答将帮助您.
You can even write inline javascript simply using # if(...){# ... #}# syntax. This faq will help you.
这篇关于如何在 Kendo 网格中从 ClientTemplate 调用 javascript 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文