Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI Using template data as a javascript variable

I am looking for a way (if there is any) to use data retrieved from the datasource, inside the template, as javascript.

Let me clarify...

In my datasource results i have a variable called ItemType. In a template i would use this variable using ${ItemType} to 'echo' it in the page.

You can use javascript inside the template by using # if (...) { console.log('test') } #.

What i want to achieve, is to use the ${ItemType} inside the template's javascript like this:

<script type="text/x-kendo-tmpl" id="dossier_template">
# var type= "${ItemType} "; #

If i can set a variable depending on the datasource item, i can use if-statements within the rest of the template like this:

# if(type == '1') {#
   <div class="type_one"></div>
# else { #
   <div class="type_two"></div>
#
like image 405
Danny Avatar asked Feb 14 '26 10:02

Danny


1 Answers

You can try this:

# var type= ItemType; #

This should also work:

# if(ItemType == '1') {#
   <div class="type_one"></div>
# else { #
   <div class="type_two"></div>
#
like image 174
Atanas Korchev Avatar answered Feb 16 '26 23:02

Atanas Korchev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!