Search code examples
kendo-uikendo-template

How to pass parameter to kendo template


I have this code:

var columns = [];

$.each(actions, function (idx, action) {
    actionColumn = { 
        template: '#if (selfActions[i].name === "' + action.name + '"){ # <input type="checkbox" /> some text   # } # '
    }   
    columns.push(actionColumn);
});

 $("#myId").kendoTreeList({
    //...
    columns: columns
});

And I want to convert to template such as:

<script id="rowLeaveTemplate" type="text/x-kendo-tmpl">
        if (selfActions[i].name === '???action.name???' ){#
            <input type="checkbox" />  some text
        # }  # 
</script>

How can I pass parameter action.name to template to replace '???action.name???'


Solution

  • Something like this:

    actionColumn = { 
        template: function(dataItem) {
            return kendo.template($("#rowLeaveTemplate").html())({ actionName:action.name });
        }
    }
    

    and kendo template itself:

    <script id="rowLeaveTemplate" type="text/x-kendo-template">
        # if (selfActions[i].name === actionName ){#
            <input type="checkbox" />  some text
        # }  # 
    </script>