简体   繁体   中英

Error when selecting iron-list item manually

  • polymer 1.4.0
  • iron-list 1.3.1

I am manually triggering selection of an item when a certain element is clicked. This works fine as long as I have selection-enabled multi-selection attributes on my iron-list. However, I would like to remove them because the associated event handlers (select on tap) interfere with mine. When I do I get polymer.html:3942 Uncaught TypeError: userArray.slice is not a function

Some loggging shows that _itemsChanged is doing Polymer.Collection.get(this.items) which expects an array of all items further down the chain, but is getting just the selected item as an object. So I've found the problem, but I don't know why it's happening or how to fix it.

It looks in the code like selection-enabled is just adding the handlers. Is that a wrong assumption? Is it always needed to do selections? Is there something wrong with my function perhaps?

This is my select function, adapted from the _selectItem function in this post's jsbin :

toggleSelect: function(e) {
  this.$.itemsList.toggleSelectionForItem(e.model.item);
},

My apologies as this question is a bit rushed. I will try to provide a fiddle later.

try changing selectedItem property instead of calling the method toggleSelectionForItem. From the description of this method it seems that it is more related to multi select property.

Solution

The code in the original post is correct, the solution is to use multi-selection but not selection-enabled .

Explanation

Since toggleSelectionForItem appears to depend on multi-selection and it is selection-enabled that fires the unwanted select we can simply remove selection-enabled to get the desired behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM