【问题标题】:How to access a method inside Kendo UI's filterable itemTemplate?如何访问 Kendo UI 的可过滤 itemTemplate 中的方法?
【发布时间】:2018-05-14 17:54:24
【问题描述】:

我有一个剑道网格,其中一列是可过滤的。但是,为了确保可过滤弹出窗口中值的正确本地化,我需要在 itemTemplate 中调用一个方法,该方法将返回数据的本地化值。

我已经尝试在示例DOJO 中实现它,它有效。但是,这不适用于我的实际代码。我的代码看起来有点像这样。剑道网格是在 Marionette View 中创建的。我真的找不到 dojo 和我的代码之间的区别。就我而言,它给出了一个错误,即该方法未定义。 对此的任何线索将不胜感激。

define(function(require) {

    var MarionetteView = Marionette.View.extend({
        init: function(){
        //init Variables
    },

    createGrid: function(){
        var kendoGrid = $("#grid").kendoGrid({
          columns: [ {
                field: "country",
              filterable: {
                    multi:true,
                  itemTemplate: function(e) {
                    //Test Method is not accessible here
                    return "<span><label><span>#= test(data.country|| data.all) #</span><input type='checkbox' name='" +                                                    e.field + "' value='#= data.country#'/></label></span>"
                    e.field + "' value='#= data.country#'/></label></span>"
                    }
                }
            }],
            filterable: true,
            dataSource: [ { country: "BG" }, { country: "USA" } ]
        });
        function test( text ){
            return text + 1;
        }

    }
    )};
    return MarionetteView;
}

【问题讨论】:

    标签: javascript kendo-ui kendo-grid


    【解决方案1】:

    之所以在你的 DOJO 中起作用,是因为该函数是在 Window 的范围内创建的。由于 Grid 也是在 Window 范围内创建的,因此您可以在项目模板中访问 test()

    在您的情况下,您的范围正在更改为 Marionette 视图。因此,如果您现在想使用 test,则必须执行以下操作:

    window.test = function(text){ //Your logic } 
    

    这应该可行。

    【讨论】:

    • 谢谢这对我有用。很想投票,但因为声誉较低而不能投票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多