[英]Polymer 1.x: Accessing 'selected' items from iron list
如何訪問元素,屬性,否則如何迭代iron-list
的selected
項目?
這是JSBin 。
那么,我們如何訪問這些選定項的值?
http://jsbin.com/duwasisoyo/1/edit?html,output _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 }
可能鐵列表不會通知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
不為空;)
來自Polymer Slack網站的@jeanpokou說:
也許您需要使用
<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
來自Polymer Slack網站的@rob說:
關鍵更改:https://jsbin.com/hiruducole/1/edit?html,輸出這是固定版本https://jsbin.com/hiruducole/1/edit?html,輸出
您需要觀察者(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; },
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.