このライブスニペットは、iron-list
を使用するWebコンポーネントを構築します。リストの各項目には削除ボタンがあり、クリックするとその項目がリストから削除されます。 アイテムが削除されると、次のアイテムはすべて上に移動しますが、最後に表示されたアイテムは表示されなくなります。Polymer - アイアンリストからアイテムを取り除くには?
this stackoverflowによると、単に鉄リストにイベントresize
を発射するだけで十分です。しかし、私のスニペットでは、これは役に立たない。 Nether iron-resize
または公式のnotifyResize関数iron-list
documentationからの関数です。
<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 ---
\t \t this.$.list.fire('iron-resize');
\t \t this.$.list.fire('resize');
\t \t this.$.list.notifyResize();
}
}
customElements.define(MyList.is, MyList);
</script>
</dom-module>
<my-list></my-list>
削除されたアイテムを隠すためにアイアンリストに指示するのはなぜですか? さらに、私は私の問題を解決しました。これは、アイロンリストにあるテンプレートのルート要素のCSSの 'display'プロパティを変更したためです。 [正解とそのデモはこちら](https://stackoverflow.com/a/47305152/4170935)をご覧ください。 – Yairopro