[英]Error when selecting iron-list item manually
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.
从此方法的描述来看,它似乎与多选择属性更相关。
The code in the original post is correct, the solution is to use multi-selection
but not selection-enabled
. 原始帖子中的代码是正确的,解决方案是使用
multi-selection
但不selection-enabled
。
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-enabled
了selection-enabled
会触发不需要的选择,因此我们可以简单地删除selection-enabled
了selection-enabled
以获得所需的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.