I am trying to delete an item from iron-list
using the following code.
<iron-list id="list" items="[[items]]" as="item"
selected-items="{{selectedItems}}"
selection-enabled multi-selection>
<template>
<my-item item="[[item]]" on-tap="_onItemTap"></my-item>
</template>
</iron-list>
...
_onItemTap: function(e) {
this.items.splice(e.model.index, 1);
}
Expected behavior
- Tap list item
- List item disappears
- Select next list item
- Next list item is selected
Actual behavior
- Tap list item
- List item does not disappear
- Select same list item (i.e., the one previously intended to be deleted)
- Next list item is actually selected (i.e., index offset by one)
Questions
- What code will result in the desired / expected behavior?
- Please provide a working jsBin sample.
This documentation on array mutation provides the following boilerplate code:
custom-element.htmlApplying that to this case:
my-element.htmlA problem with this solution, however, is that it deletes the last item from the
iron-list
, not the item at the expected index. In other words, it behaves like one would expectthis.items.pop()
.It also throws the following curious error message:
console.logSee this answer for specific syntax contributing to the problem.
Here is a working JSBin.
http://jsbin.com/qefemoloxi/1/edit?html,console,outputA summary of this page suggests this documentation as follows:
Question ReplySee this answer for full code solution.
The problem here was caused by the fact that my
item.html
file was setting and displaying properties outside theitem.
property. So, when theiron-list.(this.)splice('items', e.model.index, 1);
array mutation method was called, the nonitem
properties were not being removed from the DOM.Example:
my-list-item.html my-iron-list.html