html - 为什么我的 (selectionChange) 不断执行?
问题描述
我使用自定义多选自动完成创建了一个角度项目,该项目具有
@Output() selectionChange: EventEmitter<any[]> = new EventEmitter<any[]>();
以及下面的方法
onSelectionChange(val : any) {
const filteredValues = this.getFilteredOptionsValues();
let count = 0;
if (this.multiple) {
this.selectedValue?.filter(item => {
if (filteredValues.includes(item)) {
count++;
}
});
this.selectAllChecked = count === this.filteredOptions.length;
}
this.selectedValue = val.value;
this.selectionChange.emit(this.selectedValue);
}
我在我的其他组件中使用它
<div style="width: 100%; margin-right: 26px; margin-bottom: 15px;">
<multi-select-autocomplete class="input-medium"
[placeholder]="'Search and Select Brands'"
[options]="companies"
[display]="'name'"
[value]="'id'"
[labelCount]="10"
[label]="'Brands'"
(selectionChange)="selectBrand($event)">
</multi-select-autocomplete>
</div>
</div>
但是我遇到了一个问题,即 (selectionChange) 方法在我进行选择之前就一直在触发。
我可能出错的任何想法?
解决方案
推荐阅读
- swift - 在 Swift 中,有没有办法知道文件是否正在下载?
- excel - Excel 将循环结果输出到带有循环的每一行的新单元格
- python - DictReader 应该在错误的列数上出错
- json - 如何在 Postgres 的 JSONB 字段中编辑 JSON 对象深处的单个值?
- python - 通过比较两个字典的值来创建第三个字典
- php - 来自 php 文件的奇怪语法
- blazor - 如何在 Blazor WebAssembly 中实现外部异步操作完成?
- c# - ASP.Net Core 为我的应用程序处理了太多 cookie
- r - R 3.6.2 - SDMTools 不可用
- java - `Thread.sleep` 与 Project Loom for Java 中的虚拟线程(纤维)不同吗