Angular-tree-control的使用

需求:将具有层级的数据通过组织树的形式展现出来(样式如下图)

一、引入Angular-tree-control

1、在页面中引入Angular-tree-control的依赖:

2、将依赖添加到您的应用程序模块当中:

3、在DOM中添加Angular-tree:

说明:(1)若展示静态数据,DOM中的展示方式如下图(tree-model即为需要展示的数据数组,options用于为树添加数据,on-selection用于添加节点的选中状态,selected-node即为选中的节点)

说明:(2)若动态加载子集数据,DOM中的展示方式如下图(这里expanded-nodes的数据即为点击父级节点加载的子集数据的数组,而on-noe-toggle即为点击父级节点加载子集数据的方法)

4、为树添加数据:

说明:nodeChildren为树结构需要循环展示的数组,所以将循环的数组名字赋值给它;若要成功展示所有数据,则返回的数据必须是规则的结构,每一层级的数组名字必须是相同的(在这里循环的是数组children)。

5、到此一个完整的组织树就展示出来了。

6、参考文献:https://github.com/wix/angular-tree-control (可以在这里下载依赖)

 

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Angular使用angular-gridster库,可以通过使用其提供的事件和方法来获取拖拽后的数据。 首先,我们需要在HTML文件中设置Gridster组件,并声明一个用于展示数据的数组: ```html <gridster [options]="gridsterOptions" (gridsterItemChange)="onItemChange($event)"> <gridster-item *ngFor="let item of gridsterItems" [item]="item"> <!-- content --> </gridster-item> </gridster> ``` 在组件的.ts文件中,需要定义gridsterOptions和gridsterItems变量,并使用相关的事件和方法来获取拖拽后的数据: ```typescript import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { gridsterOptions = { // gridster options }; gridsterItems = [ // initial items ]; onItemChange(event: any) { // get gridster item change event console.log(event); // here you can access the dragged item's updated data } } ``` 在onItemChange方法中,可以通过event参数访问拖拽后的数据。它包含了当前拖拽的GridsterItemComponent实例,我们可以从中获取更新后的数据。 例如,可以通过event.item获取更新后的位置信息、尺寸信息等。如果有其他自定义的数据需要获取,可以在GridsterItemComponent中设置相关属性并在event.item中访问。 以上是使用angular-gridster获取拖拽后数据的基本方法,你可以根据自己的需求进行进一步定制和处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值