【发布时间】:2016-01-11 08:34:06
【问题描述】:
我如何访问元素、属性以及以其他方式迭代 iron-list 的 selected 项?
- 打开控制台。
- 从列表中选择两个或三个项目。
- 单击标有“在控制台中显示项目”的按钮。
- 请注意控制台输出的最后三行中的输出问题。它们显示未定义的数组长度,并且任何对象键应该为空的数组。
那么,我们如何访问这些选定项的值?
http://jsbin.com/duwasisoyo/1/edit?html,输出_showItems: function(){
console.log(this.selectedList); // Okay
console.log(this.selectedList[0]); // Okay
console.log(this.selectedList[0]['name']); // Okay
console.log(this.selectedLength); // Undefined
console.log(this.selectedKeys); // Empty array
console.log(this.selectedNames); // Empty array
}
注意:This question uses the source code of the iron-list "selected items" demo.
【问题讨论】:
-
iron-list 元素演示就是这样做的。只需查看源代码。
-
@GünterZöchbauer:本题使用你描述的铁名单demo的源码。请仔细看看这个问题。该演示直接绑定到所选项目的数据源。在这个问题中,我想访问和迭代(即操作)数据源来修改它。似乎没有办法做到这一点。
-
selectedLength、selectedKeys和selectedNames不在documentation 中...您要精确获取什么? -
@squaleLis:见我上面的评论。
-
我还想记住
selectedItems只能被读取并且更新被忽略,并且您需要使用方法来更新选定的项目。不确定,我用了一段时间。
标签: javascript polymer polymer-1.0