我无法访问<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
元素?
感谢您的帮助。
答案 0 :(得分:1)
var img = this.querySelector('.imageBoard .image img-thumbnail') as ImageElement;