我是聚合物的新手,想要开始简单的事情。我对所有术语都不太熟悉,所以我很难谷歌做正确的事。
无论如何,我发现我可以访问'浅dom'中文本的textContent?相当容易:
<!-- This is part of my-element element -->
<template>
{{textContent}} <!-- Outputs all the text -->
{{foo.textContent}} <!-- Doesn't output anything as I'd hoped it would.. -->
{{test.textContent}} <!-- Doesn't output anything as I'd hoped it would.. -->
</template>
但是,我似乎无法在主页面中访问子元素的特定文本内容:
<!-- This is part of index.html -->
<my-element>
<test>Some text here</test>
<foo>Something else</foo>
</my-element>
那么有没有办法明确地获取textContent?我知道JS可能相当容易,但我觉得这可能是一种内置的聚合方式,就像访问{{textContent}}一样。
答案 0 :(得分:1)
好的,所以这很简单。我可以在模板中执行以下操作,而不是使用胡子语法:
Foo is: <content select="foo"></content><br>
Test is: <content select="test"></content><br>
此输出:
Foo is Some text here
Test is: Something else