繁体   English   中英

如何基于angular2中复选框的选中和取消选中给出下拉值

[英]How to give dropdown values based on check and uncheck of checkbox in angular2

我有一个基于选择复选框的复选框,值必须显示在下拉列表中。 但是在这里,当我“取消选择”两个复选框,然后再次选择两个复选框并“取消选择”时,下拉列表值保持不变,不会重置。 谁能帮我解决这个问题?

DEMO

TS:

 setFaxId(index: number, faxQue: any) {
        faxQue.isChecked = (faxQue.isChecked) ? false : true;
        let filteredArr = this.faxqueuelists.filter(x=>x.faxQueueID == faxQue.faxQueueID);
        if (faxQue.isChecked) {
            this._selectedFaxQueList.push(faxQue.faxQueueID);
            this.dropDownFaxQueueList.push(filteredArr[0]);
            if(this.dropDownFaxQueueList.length == 1){
                this.userGroup.get("DefaultFaxQueue").patchValue(faxQue.faxQueueID);
            }

        } else {
            this._selectedFaxQueList.splice(this._selectedFaxQueList.indexOf(faxQue.faxQueueID), 1);
            this.dropDownFaxQueueList.splice(this._selectedFaxQueList.indexOf(faxQue.faxQueueID),1);
            this.userGroup.get("DefaultFaxQueue").patchValue("");
        }
    }

以此替换else部分:

let index = this._selectedFaxQueList.indexOf(faxQue.faxQueueID);
this._selectedFaxQueList.splice(index, 1);
this.dropDownFaxQueueList.splice(index,1);

所选元素已经从_selectedFaxQueList删除,当第二次执行indexOf() (在您的代码中)时,它不会给出正确的结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM