Polymer 如何从模板元素中获取子元素?

Polymer 如何从模板元素中获取子元素?,polymer,polymer-1.0,Polymer,Polymer 1.0,dom changePolymer.dom(e).localTarget中的事件对象e给了我我看到了一些问题,所以我将讨论它们并在最后给出一个工作示例 理解模板 Polymer.dom(e).localTarget.content让我可以访问文档片段,至少它可以在Chrome上运行。我想这里可以回答这个问题:谢谢,但这对我不起作用。它将位于dom repeat中,因此class/id将不起作用。因此,我将始终获取localTarget的第一个子对象。但是,localTarget对于有子对象的子对

dom change
Polymer.dom(e).localTarget中的事件对象e给了我
我看到了一些问题,所以我将讨论它们并在最后给出一个工作示例

理解
模板


Polymer.dom(e).localTarget.content
让我可以访问
文档片段,至少它可以在Chrome上运行。

我想这里可以回答这个问题:谢谢,但这对我不起作用。它将位于
dom repeat
中,因此class/id将不起作用。因此,我将始终获取
localTarget
的第一个子对象。但是,
localTarget
对于有子对象的子对象显示null。
  <template is="dom-if" if="[[uploadedImage1]]">
    <div id="uploadedImage1" class="row-image horizontal layout">
      foo
    </div>
  </template>
    this.$['images-container'].addEventListener('dom-change', (e)=> {
      var bob = Polymer.dom(e).localTarget;
      var sue = Polymer.dom(bob).querySelector('div')
      console.log(sue);
    });
    this.$['images-container'].addEventListener('dom-change', (e)=> {
      var bob = Polymer.dom(e).localTarget;
      var sue = this.queryEffectiveChildren(bob);
      console.log(sue);
    });
    this.$['images-container'].addEventListener('dom-change', (e)=> {
      var bob = Polymer.dom(e).localTarget;
      var sue = bob.getEffectiveChildNodes();
      console.log(sue);
    });
  }
<dom-module id="image-uploader">
  <template>
    <style include="iron-flex iron-flex-factors iron-flex-alignment">


    <div id="images-container" class="horizontal layout center wrap">

      <div hidden="[[uploadedImage1]]" class="layout vertical center-center">
        <div class="row-image horizontal layout">
          <input
            type="file"
            name="file"
            data-uploaded="uploadedImage1"
            id="image1"
            accept="image/jpeg"
            class="inputfile" />
          <label
            for="image1"
            id="image1"
            class="image-show horizontal layout center center-justified">
            <iron-icon icon="add" prefix></iron-icon>
            Upload Image
          </label>
        </div>
        <i>*Main Image</i>
      </div>

      <template is="dom-if" id="foo" if="[[uploadedImage1]]">
        <div id="uploadedImage1">
          foo
        </div>
      </template>

    </div>

  </template>

  <script>
    Polymer({
      is: 'image-uploader',
      properties: {
        uploadedImage1: {
          type: Boolean,
          value: false
        }
      },
      ready: function(e) {
          console.log(Polymer.dom(this).children.length);
<div id="container" class="style-scope my-el">
  <div id="uploadedImage1" class="style-scope my-el">
    foo
  </div>
  <template is="dom-if" id="foo" class="style-scope my-el"></template>
</div>
this.$.foo.addEventListener('dom-change', function() {
  if (this.prop1) {
    console.log(this.$$('#uploadedImage1'));
  } else {
   console.log(null);
  }
}.bind(this));