如何重置 ng-multiselect-dropdown

新手上路,请多包涵

我想重置 ng-multiselect-dropdown。有必要写成表格吗?

代码 -

应用程序组件.html

 <div>
  <p id = "node">Select a Root API Object - </p>
  <p style="width:50%">
    <ng-multiselect-dropdown [placeholder]="'Select Root API Object'" [data]="dropdownListRoot" [(ngModel)]="selectedItemsRoot" [settings]="dropdownSettingsRoot"
      (onSelect)="onItemSelectRoot($event)" (onSelectAll)="onSelectAllRoot($event)">
    </ng-multiselect-dropdown>

  </p>
</div>

应用程序组件.ts

  export class HierarchySearchComponent implements OnInit {

 onItemSelectRoot(item: any) {
    this.onlyRootItemSelect = true;  // for cypher also.

    console.log(item);
    this.rootItem = item;
    this.nodeSelect = true;

    this.rootItemText = this.rootItem.item_text;
    console.log("this.rootItemText = ", this.rootItemText);

  }

  onSelectAllRoot(items: any) {
    console.log("On Item select all" + items);
    this.nodeSelect = true;
  }

}

原文由 Techdive 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 483
2 个回答

没有必要把它写成表格。只需将 selectedItemsRoot 数组设为空即可。从元素/上下文中调用此函数 resetSelection()。如果您使用按钮清除选择,它可以是

.html

 `<button (click)="resetSelection()" >clear</button>`

.ts

 resetSelection() {
this.selectedItemsRoot = [];
}

原文由 Abidh 发布,翻译遵循 CC BY-SA 4.0 许可协议

没有必要把它放在一个表格中——如果你想清除选中的项目,只需将 selectedItemsRoot 对象设置为一个空数组。 IE

 clearSelection() {
    this.selecteditemsRoot = [];
}

并将该函数绑定到一个按钮,或使用您用来清除选择的任何其他方法调用它。

原文由 Phobos 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题