【发布时间】:2014-11-14 03:51:50
【问题描述】:
我是聚合物新手,想从简单的东西开始。我对所有术语都不太熟悉,所以我很难用谷歌搜索正确的东西。
无论如何,我发现我可以访问'shallow 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}} 一样。
【问题讨论】:
标签: javascript html data-binding polymer