【问题标题】:Values from API show up in input box but not selected checkboxes of that values using ng-multipleselect-dropdown来自 API 的值显示在输入框中,但未使用 ng-multipleselect-dropdown 选择该值的复选框
【发布时间】:2023-03-10 12:25:01
【问题描述】:

HTML 文件 ->

<ng-multiselect-dropdown
     [placeholder]="'Select section'"
     [settings]="dropdownSettings"
     [data]="dropdownList"
     [(ngModel)]="getDropdownValues"
     formControlName="sections"
>
</ng-multiselect-dropdown>

.ts 文件 ->

    this.clientMasterForm = this.formBuilder.group({
            sections: [this.getDropdownValues],
    });
    this.dropdownSettings = {
     singleSelection: false,
     idField: 'id',
     textField: 'sectionName',
     selectAllText: 'Select All',
     unSelectAllText: 'UnSelect All',
     allowSearchFilter: true,
    };
   onItemSelect(item: any) {
    let data = [];
    data.push(item);
    this.selectedDropDownData = data[0];
   }
  onSelectAll(items: any) {
   let data = [];
   data.push(items);
   this.selectedDropDownData = data[0];
  }

   this.getDropdownValues.push(JSON.parse(list).sectionName);

  this.clientMasterForm.get('sections').patchValue(this.getDropdownValues);

在这里,我得到了已经添加到下拉列表中的值,也修补了该值,但复选框中未选中输入框中显示的值

这是我的输出 ->

在这里,我得到如上图所述的输出,其中我获取数据但未在复选框中选中

【问题讨论】:

  • 可以添加JSON.parse(list)的输出
  • @Bharath 仍然无法正常工作
  • 请在此处粘贴输出

标签: angular checkbox ng-multiselect-dropdown


【解决方案1】:

ng-multiselect-dropdown 正在寻找 getDropdownValues 来预填充这些值。所以它应该具有{id: , sectionName: } 中提到的属性dropdownSettings

而不是

this.getDropdownValues.push(JSON.parse(list).sectionName);

试试

this.getDropdownValues.push({
  id: JSON.parse(list).id,
  sectionName: JSON.parse(list).sectionName
});

【讨论】:

  • 嘿@Bharath 仍然没有正确检查输入框绑定中的复选框值数据,但未填充复选框值
  • 请在此处添加list的输出
猜你喜欢
  • 1970-01-01
  • 2021-05-21
  • 1970-01-01
  • 1970-01-01
  • 2018-02-13
  • 1970-01-01
  • 1970-01-01
  • 2013-08-08
  • 1970-01-01
相关资源
最近更新 更多