如何在Kendo网格的ClientTemplate中调用JavaScript方法?

13
在Kendo网格的ClientTemplate中放置JavaScript语句是否可能? 我想在客户端计算一些数据,然后将结果放入行中。 我尝试了以下内容:
 columns.Bound("ExecutionStartDateTime").Title("SummaryLine").Width("20%").ClientTemplate("<script> scheduleForm.generateSummary(#= ExecutionStartDateTime #, 2); </script>");

然而,它没有产生任何效果。

1个回答

28

你可以使用模板文字的语法:

<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。常见问题解答将会对您有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接