Polymer Dart - 无法访问模板元素内的元素

时间:2014-08-10 20:12:18

标签: dart dart-polymer

我无法访问<template if = "{{something}}">内的元素。我已经阅读了网上发布的一些帖子,主要是解决方案涉及MutationObserver的使用。问题是我用其他模板元素链接的模板元素。下面是一个例子:

       <template repeat="{{container in containers}}">
        <!-- Tab content -->
        <div id="{{container.secondname}}" class="{{container.secondname}}">
          <template id="firstTemplate" if="{{currentContainer.photos.isEmpty}}">
              (...)
          </template>
          <template id="secondTemplate-{{container.name}}" if="{{currentContainer.photos.isNotEmpty}}">
            <div class="row">
              <div class="col col-xs-12 col-sm-12 col-md-12 col-lg-12">     
                <section class="centerStuff">
                  <template if="{{container.photosToDisplay.length < 1}}">
                    (...)
                  </template>
                  <template if="{{container.photosToDisplay.length > 0}}">
                      <template if="{{isInOverflow}}">
                        <div on-click="{{moveLeft}}" id="thumb-back"></div>
                      </template>    
                      <ul id="nav-{{container.secondname}}" class="navlistHorizontal">
                        <template repeat="{{photo in currentContainer.photosToDisplay}}">  
                          <li> 
                            <div class="mementoSpecialImage">
                              <div class="imageBoard">
                                <img src="{{photo.miniThumbnailToShow.src}}"
                                     class="image img-thumbnail"
                                     title="{{photo.title}}"
                                     on-click="{{showImage}}"
                                     id="{{photo.title}}"
                                     data-id="{{photo.id}}" >
                                </div>
                            </div> 

如何继续访问img元素?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

var img = this.querySelector('.imageBoard .image img-thumbnail') as ImageElement;