priming multiselect下拉列表,将选定的值移动到顶部



Priming-多选

想要在priming的多选下拉列表中将所选内容移动到顶部。如何实现?

我试着根据索引对选定的值进行排序。这行不通。

    items.sort((a:any, b:any) => {
            let IndexA = selected.findIndex(((i:any) => i == a[key]));
            let IndexB = selected.findIndex(((i:any) => i == b[key]));
  return 0;
});
  1. 当使用(onChange)="onSelectionChange($event)" pass$event捕获选定元素的数组时,可以执行以下操作
  2. 使用事件参数onSelectionChange(event:any)创建函数
  3. 在函数内部,您可以迭代选定的值并从列表中拼接选定的值,然后取消提升选定的元素,从而将该元素添加到数组的顶部
onSelectionChange(event:any):void {
  event?.value.foreach(selectedItem => {
     this.items.splice(this.items.indexOf(selectedItem),1) // remove the item from list
     this.items.unshift(selectedItem)// this will add selected item on the top 
  })
}

最新更新