2016-09-08 37 views
1

類a中的kendo TreeList代碼(打字稿文件):我已經從kendo模板中調用函數。kendotreelist中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

+0

您應該發佈整個A類以及它可能屬於的任何模塊。當您嘗試調用該函數時,它很重要。 – toskv

+0

@toskv添加了類 –

回答

3

如果你想使用KendoUI模板,你擁有的功能在全球(Javascript成爲)範圍來定義它們。 (Reference

只需從類A中提取FormatNumberToEn函數。

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

或者定義你的函數爲static,並呼籲A.FormatNumberToEn()內模板也可能會奏效。 (因爲我在手機上,所以無法立即測試。)

+0

謝謝。你的回答有助於解決同樣的問題。 –