TTML-引用

2020-02-11 17:09 更新

TTML 提供兩種文件引用方式 import 和 include。


import

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 的作用域

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

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>
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)