zoukankan      html  css  js  c++  java
  • JTemplate学习(四)

    注释、自定方法、模板嵌套子模板、循环输出不同class

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <!-- saved from url=(0043)http://jtemplates.tpython.com/example4.html -->
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript" src="Scripts/jTemplates/example/jquery.js"></script>
        <script type="text/javascript" src="Scripts/jTemplates/jquery-jtemplates.js"></script>
        <title>jTemplates</title>
    
        <script type="text/javascript">
            // data for testing
            $(document).ready(function () {
                var data = {
                    name: 'User list',
                    list_id: 4,
                    table: [
    					{ id: 1, name: 'Anne', age: 22, mail: 'anne@domain.com' },
    					{ id: 2, name: 'Amelie', age: 24, mail: 'amelie@domain.com' },
    					{ id: 3, name: 'Polly', age: 18, mail: 'polly@domain.com' },
    					{ id: 4, name: 'Alice', age: 26, mail: 'alice@domain.com' },
    					{ id: 5, name: 'Martha', age: 25, mail: 'martha@domain.com' }
                    ],
                    toString: function () {
                        return this.name.bold() + ' (count: ' + this.table.length + ')';
                    }
                };
    
                // attach the template
                $("#result1").setTemplateElement("template");
    
                // process the template
                $("#result1").processTemplate(data);
    
                //{**} 注释
                //
            });
        </script>
    
        <style type="text/css">
            .jTemplatesTest {
                background: #DDD;
                border: 1px solid #000;
                margin: 2em;
                 480px;
            }
    
                .jTemplatesTest * {
                    padding: 4px;
                    margin: 2px auto;
                }
    
                .jTemplatesTest td, tr {
                    border: 1px solid black;
                }
    
            .bcEEC {
                background: #EEC;
            }
    
            .bcCEE {
                background: #CEE;
            }
        </style>
    </head>
    
    <body style="zoom: 1;">
    
        <!-- Template content (Valid XHTML 1.1) -->
        <p style="display: none">
            <textarea id="template" rows="0" cols="0"><!--
                {*主模板*}
    		{#template MAIN}
    			{* this is a comment *}
    			{$T.toString()} {* $T == $T.toSource() *}
    			<table>
    				{#foreach $T.table as record}
    					{#include ROW root=$T.record}{*为子模板指定数据源,循环填充数据*}
    				{#/for}
    			</table>
    		{#/template MAIN}
    		
                {*嵌套子模板*}
    		{#template ROW}
    			<tr class="{#cycle values=['bcEEC','bcCEE']}">{*循环输出*}
    					<td>{$T.name}</td>
    					<td>{$T.mail}</td>
    			</tr>
    		{#/template ROW}
    	--></textarea>
        </p>
    
        <!-- Output elements -->
        <div id="result1" class="jTemplatesTest">
        </div>
    </body>
    </html>
    
  • 相关阅读:
    一个男人该有的气质
    有没有想过,也许一辈子你都是个小人物
    System.IO.File.WriteAllText("log.txt", "dddd");
    cn_windows_10_enterprise_version_1703_updated_june_2017_x64_dvd_10720588.iso
    Visual Studio 2015 update 3各版本下载地址
    优麒麟 16.04 LTS(长期支持)版本
    干货!最全羽毛球技术动态分解gif图
    添加缓存 绝对时间过期
    C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑
    无法解析依赖项。“Microsoft.Net.Http 2.2.29”与 'Microsoft.Net.Http.zh-Hans
  • 原文地址:https://www.cnblogs.com/xsj1989/p/5191968.html
Copyright © 2011-2022 走看看