artemplate include

include用于嵌入字模板

{{include 'template_name'}}

子模板 默认共享当前的数据 也可以自己指定数据

{{include 'template_name' template_data}}

demo1

html

<div id="content5"></div>

 

template

<script type="text/html" id="test6">
<ul>
    {{each content}}
    <li>{{$value}}</li>
    {{/each}}
</ul>
</script>
<script  id="test5" type="text/html">
    <div>
        <h3>test5:{{title}}</h3>
        <div>{{include 'test6' list}}</div>
    </div>
</script>

 

js

var data1 = {
        aa:"ewewew",
        title : 'HELLO WORLD',
        isAdmin : true,
        list :{
            content: ['新闻','军事','历史','政治']
        }

    };
    var html5=template('test5',data1);
    document.getElementById("content5").innerHTML=html5;

 

demo2

html

<div id="aa"></div>

template:

<script type='text/html' id='test3'>
    <ul>
        {{each list}}
        <li>
            {{$value}}
        </li>
        {{/each}}
    </ul>
</script>
<script type='text/html' id='test1'>
    <ul>
        {{each content}}
        <li>
            <div>{{$value.title}}</div>
            <div>{{include 'test3' $value}}</div>
        </li>
        {{/each}}
    </ul>
</script>

<script type='text/html' id='test2'>
    <h3>{{title}}</h3>
    <ul>
        {{each list}}
        <li>{{include 'test1' $value}}</li>
        {{/each}}
    </ul>

</script>

js

<script>

    var data = {
        title: "this is my first include demo",
        list: [
            {content: [
                {list: ['新闻', '军事', '历史', '政治'], title: 'aa-1-1'},
                {list: ['新闻', '军事', '历史', '政治'], title: 'aa-1-2'}
            ]},
            {content:[
                {list: ['新闻', '军事', '历史', '政治'], title: 'aa-2-1'},
                {list: ['新闻', '军事', '历史', '政治'], title: 'aa-1-1'}
            ]
            }]
    };
    var html = template('test2', data);
    document.getElementById('aa').innerHTML = html;
</script>

 

转载于:https://www.cnblogs.com/xiaofenguo/p/6672550.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值