【问题标题】:Simple node binding with polymer与聚合物的简单节点绑定
【发布时间】: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


    【解决方案1】:

    好的,这很简单。我可以在模板中执行以下操作,而不是使用 mustache 语法:

    Foo is: <content select="foo"></content><br>
    Test is: <content select="test"></content><br>
    

    这个输出:

    Foo is Some text here
    Test is: Something else
    

    【讨论】:

      猜你喜欢
      • 2016-10-03
      • 1970-01-01
      • 2017-06-03
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      • 2016-03-18
      • 2015-09-20
      • 1970-01-01
      相关资源
      最近更新 更多