This is a migrated thread and some comments may be shown as answers.

# javascript code # in template from kendo.bind or kendo.view

1 Answer 31 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kieren
Top achievements
Rank 1
Kieren asked on 26 Aug 2013, 07:10 AM
Hi

Is it possible to write JavaScript code in a template - and instantiate the template implicitly by using kendo.Bind OR kendo.View?
<script type="text/x-kendo-template" id="mytemplate">
# for (int i ... ) #
</script>
kendo.bind(jQuery('#mytemplate'), cardsViewModel);
Likewise, as part of a view template:
var cards = new kendo.View('mytemplate', {
            wrap: false,
            model: cardsViewModel
        });
        jQuery('#targetelement').html(cards.render());
Because whenever I try and use #, #= or #:, it just renders as text :(
Leads me to believe it only works if you explicitly instantiate as a template:
var inlineTemplate = kendo.template($("#javascriptTemplate").html());
I've only been able to use this notation to successfully render items:
<div data-template="my-template" data-bind="source: myItems">
               </div>
<script type="text/x-kendo-template" id="my-template">
    <span data-bind="text: this"></span>
</script>

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 28 Aug 2013, 06:26 AM
Hello Kieren,

You cannot instantiate template when using kendo.bind / kendo.init. To create template you need to do it like explained here:

http://docs.kendoui.com/getting-started/framework/templates/overview

The only exceptional cases when the templates are instantiated automatically (if you pass string instead of actual template) are when widgets have templates like the listview does.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Kieren
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or