我在git-hub样本sample link中使用聚合物铁塌陷元素在铁列表中使用一切正常工作,期望崩溃模式。单击更改切换模式时出错。 未捕获的TypeError:无法读取属性'open'为null
var moreInfo = document.getElementById('more-info'); 变为空
<div id="scrollable-element" style="overflow: auto;">
<iron-list id="_list" items="[]" as="person" scroll-target="scrollable-element" style="display: none">
<template>
<div>
<paper-card>
<div class="card-content">
<h1 class="feed_title">[[person.heading]]</h1>
<p class="feed_description">[[person.subheading]]</p>
</div>
<div class="card-actions">
<paper-button class="button-blue"> Share</paper-button>
<paper-button class="button-blue"> Explore</paper-button>
<paper-icon-button
icon="hardware:keyboard-arrow-up"
title="more info"
onclick="_toggle()"
style="float:right;">
</paper-icon-button>
<iron-collapse id="more-info" style="width:100%;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent enim ante, tempus
eget volutpat ac, cursus ac ante. Nulla facilisi. Praesent sed lacinia ligula. Donec
malesuada nisl eget quam iaculis, vel placerat justo cursus.
</iron-collapse>
<script>
function _toggle() {
var moreInfo = document.getElementById('more-info');
var iconButton = Polymer.dom(event).localTarget;
iconButton.icon = moreInfo.opened ? 'hardware:keyboard-arrow-up'
: 'hardware:keyboard-arrow-down';
moreInfo.toggle();
}
</script>
</div>
</paper-card>
</div>
</template>
</iron-list>
</div>
答案 0 :(得分:0)
我认为你似乎忘记了铁列实际上是一个重复的模板,因此你不仅可以找到一个带有该ID的元素(反复重复相同的id本身并不是一件好事。< / p>
我在尝试在dom-repeat模板中找到一个项目时遇到了类似的问题,所以问了这个问题,然后在下面的堆栈溢出问题和答案中找到答案。
Finding the element associated with a particular instance of dom-repeat