W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
TTML 提供兩種文件引用方式import和include。
import可以在該文件中使用目標(biāo)文件定義的template,如:
在 item.ttml 中定義了一個(gè)叫item的template:
<!-- item.ttml -->
<template name="item">
<text>{{text}}</text>
</template>
在 index.ttml 中引用了 item.ttml,就可以使用item模板:
<!-- index.ttml -->
<import src="item.ttml"/>
<template is="item" data="{{text: 'forbar'}}"/>
import 有作用域的概念,即只會(huì) import 目標(biāo)文件中定義的 template,而不會(huì) import 目標(biāo)文件 import 的 template。
如:C import B,B import A,在C中可以使用B定義的template,在B中可以使用A定義的template,但是C不能使用A定義的template。
<!-- A.ttml -->
<template name="A">
<text> A template </text>
</template>
<!-- B.ttml -->
<import src="a.ttml"/>
<template name="B">
<text> B template </text>
</template>
<!-- C.ttml -->
<import src="b.ttml"/>
<template is="A"/> <!-- Error! Can not use tempalte when not import A. -->
<template is="B"/>
include 可以將目標(biāo)文件除了 <template/> 外的整個(gè)代碼引入,相當(dāng)于是拷貝到 include 位置,如:
<!-- index.ttml -->
<include src="header.ttml"/>
<view> body </view>
<include src="footer.ttml"/>
<!-- header.ttml -->
<view> header </view>
<!-- footer.ttml -->
<view> footer </view>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: