Angular 2 :带排序的双列表组件
创始人
2024-10-15 14:30:09
0

以下是一个基于Angular 2的带排序的双列表组件的解决方法的代码示例:

  1. 创建一个双列表组件的文件,例如dual-list.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-dual-list',
  templateUrl: './dual-list.component.html',
  styleUrls: ['./dual-list.component.css']
})
export class DualListComponent {
  leftList: string[] = ['Item 1', 'Item 2', 'Item 3'];
  rightList: string[] = [];

  moveRight() {
    const selectedItems = this.leftList.filter(item => item.selected);

    this.rightList = this.rightList.concat(selectedItems);
    this.leftList = this.leftList.filter(item => !item.selected);
  }

  moveLeft() {
    const selectedItems = this.rightList.filter(item => item.selected);

    this.leftList = this.leftList.concat(selectedItems);
    this.rightList = this.rightList.filter(item => !item.selected);
  }

  sortList(list: string[]) {
    list.sort((a, b) => a.localeCompare(b));
  }
}
  1. 创建一个双列表组件的HTML模板文件,例如dual-list.component.html

Left List

  • {{item}}

Right List

  • {{item}}
  1. 创建一个双列表组件的CSS文件,例如dual-list.component.css
.selected {
  background-color: #ccc;
}
  1. 在需要使用双列表组件的父组件中,如app.component.html文件中添加以下代码:

这样就可以在父组件中使用这个带排序的双列表组件了。

相关内容

热门资讯

揭秘一下!wepoker开辅助... 揭秘一下!wepoker开辅助能查到吗,hhpoker辅助器,第三方教程(有挂软件);原来确实真的有...
玩家必看教程!pokernow... 自定义aapoker怎么设置提高好牌几率系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑...
推荐十款!大菠萝手游辅助,we... 推荐十款!大菠萝手游辅助,wepoker破解器,技巧教程(有挂透明);1分钟了解详细教程(微信 13...
专业讨论!拱趴大菠萝怎么开挂,... 专业讨论!拱趴大菠萝怎么开挂,wejoker开挂,靠谱教程(有挂透明),支持语音通讯、好友开房及战队...
技巧知识分享!hhpoker买... 技巧知识分享!hhpoker买挂,hhpoker有没有作弊挂,黑科技教程(有挂辅助);原来确实真的有...
热门推荐!pokemmo内置修... 热门推荐!pokemmo内置修改器,wejoker辅助器要钱玩吗,技巧教程(有挂软件);原来确实真的...
新手必备!aapoker破解侠... 1、新手必备!aapoker破解侠是真的吗,epoker透视底牌,科技教程(有挂攻略);详细教程。2...
揭秘关于!wepoker透视脚... 揭秘关于!wepoker透视脚本免费app,pokerworld软件,AA德州教程(有挂技巧);小薇...
总算了解!wepoker透视脚... 总算了解!wepoker透视脚本是什么,wepoker有机器人吗,力荐教程(有挂软件);致您一封信;...
六分钟了解!pokemmo脚本... 自定义wepoker数据分析工具系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅...