【问题标题】:Not able to call function in typescript from kendo template in kendotreelist无法从 kendotreelist 中的 kendo 模板调用打字稿中的函数
【发布时间】:2017-01-16 00:11:20
【问题描述】:

A 类(打字稿文件)中的 Kendo TreeList 代码:我已经从 kendo 模板调用了一个函数。

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) { }
    }
    } 

收到错误function FormatNumberToEn is undefined

【问题讨论】:

  • 您应该发布整个 A 类以及它可能属于的任何模块。当您尝试调用该函数时,这很重要。
  • @toskv 添加了课程

标签: javascript jquery .net typescript kendo-ui


【解决方案1】:

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

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

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

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

【讨论】:

  • 谢谢。您的回答帮助解决了同样的问题。
猜你喜欢
  • 1970-01-01
  • 2013-02-25
  • 1970-01-01
  • 2022-01-07
  • 2017-11-23
  • 2016-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多