當我從 NG Multiselect 下拉串列中選擇一個專案時,我似乎無法弄清楚如何更改不同的布林值。
在我的 app.component.ts
ngOnInit() {
this.dropdownList = [
{ item_id: 1, item_text: 'option 1' },
{ item_id: 2, item_text: 'option 2'},
{ item_id: 3, item_text: 'option 3'},
{ item_id: 4, item_text: 'etc' },
{ item_id: 5, item_text: 'etc' }
];
this.dropdownSettings = {
singleSelection: false,
idField: 'item_id',
textField: 'item_text',
selectAllText: 'Selecteer allemaal',
unSelectAllText: 'Verwijder selectie',
itemsShowLimit: 3,
allowSearchFilter: true
};
}
onItemSelect(item: any) {
console.log(item);
}
onSelectAll(items: any) {
console.log(items);
}
}
上面的代碼作業正常。當我選擇一個專案時,它會登錄到控制臺
我的目標是在選中 item_id 1 時,將布林值設定為 true。像這樣的東西(但不起作用):
onItemSelect(item: any) {
if(this.dropdownList.idField == 1) {
this.option1boolean = true
}
if (this.dropdownList.idField == 2) {
this.option2boolean = true
}
}
提前致謝
uj5u.com熱心網友回復:
使用 item.item_id 代替 this.dropdownList.idField
public onItemSelect(item: any) {
if (item.item_id === 1) {
this.option1boolean = true;
}
if (item.item_id === 2) {
this.option2boolean = true;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/532600.html
標籤:有角度的
上一篇:我對angularformarrayTypeError有問題:無法讀取未定義的屬性(讀取“0”)
下一篇:如果值發生變化,則僅從流中獲取值