如何访问元素,属性以及以selected
的{{1}}项进行迭代?
那么,我们如何访问这些选定项目的值?
http://jsbin.com/duwasisoyo/1/edit?html,outputiron-list
注意:This question uses the source code of the iron-list
"selected items" demo。
答案 0 :(得分:0)
也许铁列表没有通知selectedList上的更改。您可以将方法更改为
_showItems: function(){
console.log(this.selectedList);
console.log(this.selectedList[0]);
console.log(this.selectedList[0]['name']);
console.log(this._computeSelectedItemsLength(this.selectedList));
console.log(this._computeSelectedKeys(this.selectedList));
console.log(this._computeSelectedNames(this.selectedList));
}
此外,您还应该更改:
_computeSelectedNames: function(ob) {
var out = [];
for(x in ob){
out.push(ob[x]['name']);
}
return out;
},
啊,添加控件以检查selectedList
是否为空;)
答案 1 :(得分:0)
也许您需要使用
<array-selector id="selector" items="{{employees}}" selected="{{selected}}" multi toggle></array-selector>
像这里建议https://www.polymer-project.org/1.0/docs/devguide/templates.html#array-selector
答案 2 :(得分:0)
主要变化:https://jsbin.com/hiruducole/1/edit?html,output此处是固定版本https://jsbin.com/hiruducole/1/edit?html,output
你需要观察者(selectedItems。*)
然后您可以使用更改记录来确定更改内容
https://www.polymer-project.org/1.0/docs/devguide/properties.html#array-observation
你也可以观察(selectedItems.splices),但我懒惰,只做(selectedItems。*),它会捕捉到任何变化。
以下是对变更记录及其他内容的解释:https://www.polymer-project.org/1.0/docs/devguide/properties.html#deep-observation
/** / Before
selectedLength: {
computed: '_computeSelectedLength(selectedItems)'
},
/**/
// After
selectedLength: {
computed: '_computeSelectedLength(selectedItems.*)'
},
...
/** / Before
_computeSelectedLength: function(ar) {
return ar.length;
},
/**/
// After
_computeSelectedLength: function(record) {
return record.base.length;
},