简体   繁体   English

手动选择铁清单项目时出错

[英]Error when selecting iron-list item manually

  • polymer 1.4.0 聚合物1.4.0
  • iron-list 1.3.1 铁清单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. 只要我在铁清单中具有selection-enabled multi-selection属性,此方法就可以正常工作。 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 当我得到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. 某些记录显示_itemsChanged正在执行Polymer.Collection.get(this.items) ,该操作期望所有项目的数组位于链的更下游,但仅将所选项目作为对象。 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. 看起来像selection-enabled的代码只是添加处理程序。 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 : 这是我的选择功能,改编自_selectItem在功能上这个帖子的 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. 尝试更改selectedItem属性,而不是调用方法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 . 原始帖子中的代码是正确的,解决方案是使用multi-selection但不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. 由于toggleSelectionForItem似乎取决于multi-selection并且selection-enabledselection-enabled会触发不需要的选择,因此我们可以简单地删除selection-enabledselection-enabled以获得所需的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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