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)系方式:
更多建議: