html - 如何重置 ng-multiselect-dropdown

标签 html angular drop-down-menu dropdown

我想重置 ng-multiselect-dropdown。有必要把它放在表格中吗?

代码 -

app.component.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>

app.component.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;
  }

}

最佳答案

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

.html

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

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

关于html - 如何重置 ng-multiselect-dropdown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53114750/

相关文章:

javascript - 直接连接notepad++和浏览器textarea

html - 修复右侧下拉菜单和导航菜单

javascript - 如果用户在没有选择文件的情况下打开并关闭它,如何防止将输入文件加倍

html - 我的文字位于页脚下方的原因是什么?

javascript - 如何将响应分配给 Angular 4中的变量?

javascript - 如何使用 excel 中的列进行解析以将其转换为 JSON

angular - ngx-翻译 : Cannot read property 'currentLang' of undefined

css - 悬停在第一个选项上时下拉菜单消失(博主)

c# - 更新在 Repeater 中生成的 DropDownList 的值

html - <li> 元素在其中一个元素中的文本溢出时会失去所需的对齐方式