javascript - 无法从 kendotreelist 中的 kendo 模板调用 typescript 中的函数

标签 javascript jquery .net typescript kendo-ui

Kendo TreeList code in class A (typescript file): I have given call to a function from kendo template.

export class A{                        
            drillDownDataSource: any;        
            constructor() {               
                    this.GetStatutoryIncomeGridViewData();
            }    
            GetStatutoryIncomeGridViewData() {        
                $.ajax({
                    type: 'POST',
                    url: 'Controller/Action/',
                    data: stfilterData,
                    success: function (data) {
                   $("#grid").kendoTreeList({
                    dataSource: data,                                       
                    columns: [
                 { field: "Transaction1",
template:kendo.template("#=FormatNumberToEn(Transaction1)#").bind(this) },
                                        }                    
                });
            });

      public FormatNumberToEn(value) { }
    }
    } 

出现错误函数FormatNumberToEn未定义

最佳答案

如果您想在 KendoUI 模板中使用函数,您必须在全局 (JavaScript-) 范围中定义它们。 (Reference)

只需从类 A 中提取 FormatNumberToEn 函数即可。

export class A { 
    /* class definition */ 
}
function FormatNumberToEn(value) { /* function logic */ }

或者将函数定义为static 并在模板内调用A.FormatNumberToEn() 也可能有效。 (因为我在移动设备上,所以现在无法测试。)

关于javascript - 无法从 kendotreelist 中的 kendo 模板调用 typescript 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39384524/

相关文章:

javascript - 使用AMQP维护与远程 worker 的长期连接

javascript - 添加数组中的所有值 JavaScript/jquery

javascript - 如何在页面加载中将启用属性设置为 highcharts 行

c# - ActiveX VLC 播放器事件不工作

c# - 为什么 Linq 扩展方法不位于 IEnumerator 而不是 IEnumerable 上?

javascript - Angular $范围服务: How does it work?

javascript - 使用 ORM(如 ActiveRecord)为 Web API 定义模型时, 'Type Tables'(如 BOOK_TYPE 表)的重要性

javascript - HTML5 Canvas 填充曲线下区域

javascript - jQuery 窗口滚动事件。每滚动 XX 像素

c# - 巴克莱加密 asp.net (VB to c#)