我一直在尝试在Polymer项目中选择一个计数器。我的组件收到许多带有名称和子主题的过滤器。
对象看起来像这样:
filters = {name: "Health Sciences", subtopic: (3) ["Anatomy", "Cardiology",
"Clinical Medicine"]},{name: "Information Technology", subtopic: Array(5)}
然后我的聚合物下拉列表
<template is="dom-repeat" items="{{filters}}" as="chip">
<div class="block">
<paper-dropdown-menu id="[[chip.name]]" class="full-width" label="compute(chip.name, selectedFilters)" label="width: 100%" ignore-select>
<!-- SUBITEMS -->
<paper-listbox class="listbox-width" slot="dropdown-content" class="dropdown-content" multi>
<template is="dom-repeat" items="{{chip.subtopic}}" as="option" >
<paper-item>
<paper-checkbox on-change="checkboxChanged" data-name$="[[chip.name]]" value="[[option]]">[[option]]</paper-checkbox>
</paper-item>
</template>
</paper-listbox>
</paper-dropdown-menu>
</div>
</template>
所以问题在于计算函数会更改所有标签上的值(因为selectedFilters只是一个变量,用于计算所有过滤器中的选定项目),我想知道是否可以在正确的过滤器中通知选定项目的数量。名称路径
_compute(name, selectedFilters){
return name + " ["+this.selectedFilters+"]";
}
也许在选择处理程序之下?
checkboxChanged(event) {
// event.target.dataset.name;
var target = event.target.dataset.name;
var value = event.target.value;
var status = event.target.checked;
// console.log("event value", value, "event target ", target, " event status ", status);
this.dispatchEvent(new CustomEvent('filter-chip-event', {
bubbles: true,
detail: { target: target, value: value, status: status },
composed: true
}));
if (status == true){
// var nameID = target
// this.$.nameID.label = target +" "+ 1
console.log('chip.name', target +" ["+ 1+"]" );
//this.chip.name = target +" "+ 1;
// this.selectedFilters += 1;
} else if(status == false){
this.chip.name = target +" "+ 0;
// this.selectedFilters -=1;
}
}
提前感谢您的见解!