html [mobile] [kendo]模板绑定样本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html [mobile] [kendo]模板绑定样本相关的知识,希望对你有一定的参考价值。

<!--

Kendo UI Templates use a simple templating syntax called hash templates. With this syntax, the # (hash) sign 
is used to mark areas in a template that should be replaced by data when the template is executed. 
The # character is also used to signify the beginning and end of custom Javascript code inside the template.

There are three ways to use the hash syntax:
--------------------------------------------
1. Render values as HTML: #= #. RENDERS SPECIAL HTML CHARS (like &#9679;) ALSO
2. Use HTML encoding to display values: #: #.
3. Execute arbitrary Javascript code: # if (true) { # ... non-script content here ... # } #.
   Hash Literals

If your template includes a literal # character, which is not part of a binding expression and is not a script 
code marker, then you must escape that character or it causes a template compilation error. For example, this can 
happen if a # is used inside a hyperlink URL or a CSS color value. Literal # in Javascript strings are escaped 
via \\\\#, while literal # in external HTML script templates are escaped via \\#.

-->

<div id="example"></div>
<script>
    var template = kendo.template("<div id='box'>#= firstName #</div>");
    var data = { firstName: "Todd" }; //A value in JavaScript/JSON
    var result = template(data); /Pass the data to the compiled template
    $("#example").html(result); //display the result
</script>

=======================================================================================================
=======================================================================================================

<div id="listView"></div>
<!-- put contents of this template into JavaScript declared one -->
<script id="scriptTemplate" type="text/x-kendo-template">
    <ul style="color:red;">
    # for (var i = 0; i < data.length; i++) { #
        <li>#= data[i] #</li>
    # } #
    </ul>
</script>
<script>
  $(document).ready(function(){
    var data = ["Able", "Ben", "Conn"]; 
    var jsTemplate = kendo.template("<ul style='color:blue;'> # for (var i = 0; i < data.length; i++) { # <li>#= data[i] #</li> # } # </ul>");
    var scriptTemplate = kendo.template($("#scriptTemplate").html());
    function renderScriptTemplate() {
      $("#listView").html(scriptTemplate(data));
    }
    function renderJsTemplate() {
      $("#listView").html(jsTemplate(data));
    }
  });
</script>

=======================================================================================================
=======================================================================================================

<script type="text/x-kendo-template" id="preset-timers-template">
    <label id="preset-${id}">
        ${title}
        <input type="checkbox" onchange="selectPresetTimerOnChange(this, ${id})" />
    </label>
</script>
<script type="text/x-kendo-template" id="custom-timers-template">
    <label id="custom-${id}">
        ${title}
        <input type="checkbox" onchange="selectCustomTimerOnChange(this, ${id})" />
    </label>
</script>
<script type="text/x-kendo-template" id="custom-timers-grid-template">
    <div style="font-size: 0.8em">${date}</div>
    <div>
        ${title}
        <a class="listview-btn" data-role="button" data-icon="compose" onclick="${onClickEvent}"></a>
    </div>
</script>

=======================================================================================================
=======================================================================================================

<div id="example"></div>

<script id="javascriptTemplate" type="text/x-kendo-template">
    <ul>
    # for (var i = 0; i < data.length; i++) { #
        <li>#= myCustomFunction(data[i]) #</li>
    # } #
    </ul>
</script>

<script type="text/javascript">
    // use a custom function inside the template. Must be defined in the global JavaScript scope
    function myCustomFunction (str) {
        return str.replace(".", " ");
    }

    //Get the external template definition using a jQuery selector
    var template = kendo.template($("#javascriptTemplate").html());

    //Create some dummy data
    var data = ["Todd.Holland", "Steve.Anglin", "Burke.Ballmer"];

    var result = template(data); //Execute the template
    $("#example").html(result); //Append the result
</script>

=======================================================================================================
=======================================================================================================

<script id="javascriptTemplate" type="text/x-kendo-template">
    # var myCustomVariable = "foo"; #
    <p>
        #= myCustomVariable #
    </p>
</script>

=======================================================================================================
=======================================================================================================

<ul id="users"></ul>

<script type="text/x-kendo-template" id="myTemplate">
    #if(isAdmin){#
        <li>#: name # is Admin</li>
    #}else{#
        <li>#: name # is User</li>
    #}#
</script>

<script type="text/javascript">
    var templateContent = $("#myTemplate").html();
    var template = kendo.template(templateContent);

    //Create some dummy data
    var data = [
        { name: "John", isAdmin: false },
        { name: "Alex", isAdmin: true }
    ];

    var result = kendo.render(template, data); //render the template

    $("#users").html(result); //append the result to the page
</script>

=======================================================================================================
=======================================================================================================

<script id="javascriptTemplate" type="text/x-kendo-template">
    <h4>#= $("\#theSpan").text()  #</h4>
</script>

以上是关于html [mobile] [kendo]模板绑定样本的主要内容,如果未能解决你的问题,请参考以下文章

无法使用“data-bind=source:”将 Kendo Mobile ListView 绑定到数据

如何在 mvc kendo ui 网格中绑定列的客户端模板中将“this”作为函数参数发送?

在 Kendo Scheduler 自定义模板中绑定 DropDownList(ASP.NET MVC Wrapper 版本)

Kendo Mobile 的 Kendo AutoComplete?

在 Kendo 网格中绑定事件

kendo-template绑定中row-template中的多行