这个实时片段构建了一个使用iron-list
. 列表中的每个项目都有一个删除按钮,单击该按钮可从列表中删除该项目。当一个项目被移除时,所有下一个项目都会向上移动,但最后一个显示的项目会保留而不是消失。
根据这个 stackoverflow,只需触发resize
Iron-list 上的事件就足够了。但在我的片段中,这没有帮助。iron-resize
官方iron-list
文档中的或 notifyResize 函数都没有。
<script src="https://polygit.org/components/webcomponentsjs/webcomponents-loader.js"></script>
<link rel="import" href="https://polygit.org/components/polymer/polymer-element.html">
<link rel="import" href="https://polygit.org/components/iron-list/iron-list.html">
<link rel="import" href="https://polygit.org/components/paper-button/paper-button.html">
<dom-module id="my-list">
<template>
<iron-list id="list" items="{{items}}">
<template>
<div style="display:flex; justify-content: space-between; align-items: center;">
<div style="margin: 20px; ">
{{item}}
</div>
<paper-button on-tap="_onDeleteClicked"
style="background: red; color: white;">Remove</paper-button>
</div>
</template>
</iron-list>
</template>
<script>
class MyList extends Polymer.Element {
static get is() { return "my-list"; }
// set this element's employees property
constructor() {
super();
this.items = [1,2,3,4];
}
_onDeleteClicked(event){
this.splice("items", event.model.index, 1);
// ---- any resize call doesn't help a thin ---
this.$.list.fire('iron-resize');
this.$.list.fire('resize');
this.$.list.notifyResize();
}
}
customElements.define(MyList.is, MyList);
</script>
</dom-module>
<my-list></my-list>