如何在 kendo 中调用函数

How to call a function in kendo

我想通过如下调用方法格式化 mt x 轴标签:

xAxis: {
   labels: {
     template: "#=  shortLabels(value) #"
      },
}


function shortLabels(value) {
    var strValue = kendo.toString(value)
    strValue = strValue + "";
    strValue = strValue.substring(1)
    return strValue;
}

但是我得到

shortLabels is not defined error

基本上它不会调用那个方法。

http://jsfiddle.net/3yhbyy2g/31/

您可以在 kendo 模板中设置函数。是不是很漂亮,你知道,但是有效:

<script id="labelTemplate" type="text/x-kendo-template">
    #
    var strValue = kendo.toString(value)
    strValue = strValue + "";
    strValue = strValue.substring(1);
    #
    #= strValue #
</script>

并在图表中 属性:

labels: {
    template: kendo.template($("#labelTemplate").html())
}

Fiddle.