Kendo UI模板问题

时间:2013-06-26 19:33:36

标签: kendo-ui

我想这样做http://jsfiddle.net/kfEfw/115/ 但是在kendo.template(....)中我想检查一个变量的值。 在具体的例子中,它不识别x变量,我想 知道是否有办法在模板中传递x。

var temp = 0; //i want to pass this variable in the template and check it's value
/if temp = 0 I need to render sth and if temp has other value I want to render sth else
window.kendouiTemplate = kendo.template("<div><h1 class='header'><#= data.header#></h1><ul
class='list'><# for (var i = 0, l = data.list.length; i < l; i++) {
#><#if(data.list[i]%2==0){#><li class='item'><#= data.list[i] #></li><#}#><# } #></ul>
</div>", {useWithBlock:false});

提前致谢, 阿耳忒弥斯

1 个答案:

答案 0 :(得分:0)

请参阅此处的演示 - &gt; http://demos.kendoui.com/web/templates/index.html

所以在your case

HTML

<div id="results"></div>

<script type="text/x-kendo-template" id="template">
    <div>
        <h1 class='header'><#= data.header #></h1>
        <h2 class='header2'><#= data.header2 #></h2>
        <h3 class='header3'><#= data.header3 #></h3>
        <h4 class='header4'><#= data.header4 #></h4>
        <h5 class='header5'><#= data.header5 #></h5>
        <h6 class='header6'><#= data.header6 #></h6>
        <ul class='list'>
            <# for (var i=0 , l=data.list.length; i < l; i++) { #>
                <#if(data.list[i]%2==0){#>
                    <li class='item'>
                        <#=data.list[i] #>
                    </li>
                    <#}#>
            <# } #>
        </ul>
    </div>    
</script>

的JavaScript

window.sharedVariables = {
    header: "Header",
    header2: "Header2",
    header3: "Header3",
    header4: "Header4",
    header5: "Header5",
    header6: "Header6",
    list: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
};
var temp = 0; //i want to pass this variable in the template and check it's value
var template = kendo.template($("#template").html()); // your kendo template

function preview() {
    $("#results").html(template(sharedVariables));
}

preview();