polymer this.$ 集合

标签 polymer polymer-1.0

我正在阅读事件指南和指南的开头,它说:

You can also add an event listener to any element in the this.$ collection using the syntax nodeId.eventName.



什么是this.$收藏?

最佳答案

this.$包含从 Automatic node finding 创建的节点:

Polymer automatically builds a map of statically created instance nodes in its local DOM, to provide convenient access to frequently used nodes without the need to query for them manually. Any node specified in the element's template with an id is stored on the this.$ hash by id.

Note: Nodes created dynamically using data binding (including those in dom-repeat and dom-if templates) are not added to the this.$ hash. The hash includes only statically created local DOM nodes (that is, the nodes defined in the element's outermost template).



<head>
  <base href="https://polygit.org/polymer+1.6.0/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link rel="import" href="polymer/polymer.html">
</head>

<body>
  <x-foo></x-foo>

  <dom-module id="x-foo">
    <template>
      <div id="div1">foo</div>
      <div id="div2">bar</div>
      <div id="div3">baz</div>
    </template>
    <script>
      HTMLImports.whenReady(function() {
        Polymer({
          is: 'x-foo',
          ready: function() {
            console.log('div1', this.$.div1.textContent);
            console.log('div2', this.$.div2.textContent);
            console.log('div3', this.$.div3.textContent);
          }
        });
      });
    </script>
  </dom-module>
</body>

关于 polymer this.$ 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39432359/

相关文章:

javascript - 单击 'paper-tabs' 后页面才会显示

typescript - 观察 Polymer 中的数组元素不适用于 bool 绑定(bind)

polymer - 如何通过 shadow-dom 将全局 css 应用到 web 组件

polymer 1.0 : Does <iron-meta> support binding to dynamic variables?

css - 在 polymer 中加载外部 css 的条件模板

dart - Polymer linkPaths 不会在更改等时触发

javascript - 使用带铁图标的纸按钮上的点击来实现不同的当前目标

javascript - polymer 铁模验证至少选中一个复选框

javascript - 在 Polymer 中动态生成 SVG 样式

javascript - Polymer.js 输入范围的默认参数