最近在做一个树节点的上下移动然后实现排序的问题。直接看图:

实现已选查询条件的上下移动。结合了primeng 的picklist 组件。

下面是html代码

  <p-tabPanel header="查询条件">
<div class="row selfHeight" style="margin-left: 10px;">
<div class="col-4 selfHeight" style="padding: 0px;">
<div style="margin:0 0 10px 0">所有可选查询条件</div>
<div style="margin: 0px 6px;width: 100%">
<select class="select form-control radius selfHeight"
style="padding:0.2rem 0.75rem;height:30px;margin-left: -6px;width: 100%"
(change)="changeQueryConditionSelect($event.target.value)">
<option *ngFor="let values of selectData" value="{{values.attrGroupId}}">
{{values.attrGroupName}}
</option>
</select>
</div>
<p-tree [value]="leftQueryCondition" selectionMode="multiple" [(selection)]="selectLeftCondition"
(onNodeSelect)="queryConditionLeftNodeSelect($event)"
[style]="{'height':'calc(100% - 64px)','width':'100%','overflow':'auto','border-color':'#e0e0e0','color':'#333333','font-size':'13px'}">
</p-tree>
</div>
<div class="col-2" style="padding: 0px;margin-top: 120px;text-align: center">
<div style="margin-bottom: 10px">
<button type="button" class="btn btn-clickStyle radius pointer" (click)="moveRightCondition()">
<i class="fa fa-angle-double-right" aria-hidden="true"></i>
</button>
</div>
<div>
<button type="button" class="btn btn-clickStyle radius pointer" (click)="moveLeftCondition()">
<i class="fa fa-angle-double-left" aria-hidden="true"></i>
</button>
</div>
</div>
<div class="col-4 selfHeight" style="padding: 0px;">
<div style="margin:0 0 10px 0">已选查询条件</div>
<p-tree [value]="rightQueryCondition" selectionMode="multiple" [(selection)]="selectRightCondition"
(onNodeSelect)="queryConditionRightSelect($event)"
[style]="{'height':'calc(100% - 34px)','width':'100%','overflow':'auto','border-color':'#e0e0e0','color':'#333333','font-size':'13px'}">
<ng-template let-node pTemplate="default">
{{node.label}}
<select [(ngModel)]="node.symbol" type="text">
<option *ngFor="let values of operation" value="{{values.enumvalCode}}">{{values.enumvalName}}</option>
</select>
</ng-template>
</p-tree>
</div>
<div class="col-2" style="padding: 0px;margin-top: 120px;text-align: center">
<div style="margin-bottom: 10px">
<button type="button" class="btn btn-clickStyle radius pointer" (click)="moveUp()">
<i class="fa fa-angle-up" aria-hidden="true"></i>
</button>
</div>
<div>
<button type="button" class="btn btn-clickStyle radius pointer" (click)="moveDown()">
<i class="fa fa-angle-down" aria-hidden="true"></i>
</button>
</div>
</div>
</div> </p-tabPanel>

下面是ts代码:

moveUp() {  //右侧选只选中一个时才能移动
if (this.selectRightCondition && this.selectRightCondition.length==1) {
let data = this.rightQueryCondition;
let index = 0;
data.forEach((record, i) => {
if (record['fieldCode'] === this.selectRightCondition[0]['fieldCode']) {
return index = i;
}
})
var temp;
if (index === 0 || index > data.length - 1) {
this.rightQueryCondition = data;
} else {
temp = data[index];
data[index] = data[index - 1];
data[index - 1] = temp;
this.rightQueryCondition = data;
}
}
} moveDown() {
if (this.selectRightCondition && this.selectRightCondition.length==1) {
let data = this.rightQueryCondition;
let index = 0;
data.forEach((record, i) => {
if (record['fieldCode'] === this.selectRightCondition[0]['fieldCode']) {
return index = i;
}
})
var temp;
if (index === data.length - 1 || index < 0) {
this.rightQueryCondition = data;
} else {
temp = data[index];
data[index] = data[index + 1];
data[index + 1] = temp;
this.rightQueryCondition = data;
}
}
}

最新文章

  1. 一道Twitter面试题
  2. iOS开发UI篇—UITableview控件基本使用
  3. 监听spring加载完成后事件
  4. uml类关系
  5. Apache中RewriteCond规则参数介绍
  6. Ubuntu下安装mysql-python包
  7. MySQL性能状态查看方式
  8. RunLoop-b
  9. 无线wifi-PJ-之在开启WPS下使用reaver
  10. Sigmoid function in NN
  11. PHP环境出现时区问题
  12. 数独问题的介绍及POJ 2676-Sudoku(dfs+剪枝)
  13. java与javac的区别
  14. ubuntu桌面不显示菜单
  15. MongoDB基础教程系列--第四篇 MongoDB 查询文档
  16. HBASE表设计
  17. [C]\x字符转义序列
  18. myeclipse中的classpath .
  19. javascript 跨域请求详细分析(终极跨域解决办法)
  20. Status: Checked in and viewable by authorized users 出现在sharepoint 2013 home 页面

热门文章

  1. 4、python数据类型之列表(list)
  2. linux下rename命令使用(可以实现文件批量重名)
  3. P2675 《瞿葩的数字游戏》T3-三角圣地
  4. 练习九:time.sleep方法
  5. QT LCDNumber使用
  6. Windows安全认证是如何进行的?[NTLM篇]
  7. Docker | 第三章:Docker常用命令
  8. 【转】c# winform 创建文件,把值写入文件,读取文件里的值,修改文件的值,对文件的创建,写入,修改
  9. linux cached过高导致性能变低
  10. springboot 学习笔记(九)