Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng-zorro-tree

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-zorro-tree

在 `ng-tree-antd`的基础上,根据业务需要修改而成。

  • 0.3.0
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

NgZorroTree

ng-tree-antd的基础上,根据业务需要修改而成。

面向后端平级数据,由组件自身身材需要的嵌套结构:

后端返回数据格式:

[
  {
    zpid:'',          // 父节点id
    zid:'1',          // 节点自身id
    zname:'状态监控',  // 节点名称
  },
  {
    zpid:'',
    zid:'2',
    zname:'设备控制',
  },
  {
    zpid:'',
    zid:'11',
    zname:'设备控制2',
  },
  {
    zpid:'11',
    zid:'12',
    zname:'设备控制2-2',
  },
  {
    zpid:'11',
    zid:'13',
    zname:'设备控制2-2',
  },
  {
    zpid:'13',
    zid:'14',
    zname:'设备控制2-2',
  }
]

组件内部的格式:

[
  {
    pid:'',
    id:'1',
    name:'状态监控',
  },
  {
    pid:'',
    id:'2',
    name:'设备控制',
  },
  {
    pid:'',
    id:'11',
    name:'设备控制2',
    children:[
      {
        pid:'11',
        id:'12',
        name:'设备控制2-2',
      },
      {
        pid:'11',
        id:'13',
        name:'设备控制2-2',
        children:[        
          {
            pid:'13',
            id:'14',
            name:'设备控制2-2',
          }        
        ]
      },
    ]
  },
]

Dependencies

  • angular-tree-component ^5.2.0

tree

API

NameTypeDefaultSummary
nzNodesany[]{zpid:'',zid:'2',zname:'设备控制','checked':true},
nzNodeKeysObject外部数据与内部数据key的转换,实现面向后端 ,
示例: nodeKeys={'pid':'zpid','id':'zid','name':'zname','checked':'zchecked','disableCheckbox':'zdisableCheckbox',
nzCheckablebooleanfalse在节点之前添加一个复选框
nzShowLinebooleanfalse显示了一个连接线
nzOptionsTreeOptionssee options,最常用为loadChildren来实现懒加载
nzEventEventEmitternode 上的各种事件的集合

treeselect

API

NameTypeDefaultSummary
nzTreeDataany[]示例: {zpid:'',zid:'2',zname:'设备控制'}
nzTreeKeysObject外部数据与内部数据key的转换,实现面向后端 ,
示例: nodeKeys={'pid':'zpid','id':'zid','name':'zname','checked':'zchecked','disableCheckbox':'zdisableCheckbox',
nzLazyLoadbooleanfalse加载方式,设置为true时为懒加载
nzOptionsbooleanfalsesee options,最常用为loadChildren来实现懒加载

懒加载

import { Component } from '@angular/core';
import {KEYS, lazyloadNode} from './constant';
import {NzTreeService} from '../components/providers/nz-tree.service';
import {HttpClient} from '@angular/common/http';

@Component({
  selector: 'demo-async',
  template: `
  <h2>懒加载节点</h2>
  <nz-tree [nzNodes]="nodes"
           [nzShowLine]="true"
           [nzCheckable]="true"
           [nzOptions]="options"
           [nzNodeKeys]="nodeKeys"
           [nzLazyLoad]="true"
           (nzEvent)="onEvent($event)"></nz-tree>
  `
})
export class DemoAsyncComponent {
  nodeKeys=KEYS;

  nodes = lazyloadNode;

  options = {
    getChildren: (node: any) => {
      return this.getData(node.id);
    }
  };

  constructor(public nzTreeService:NzTreeService,public http: HttpClient){

  }

  getData(id:string){
    return new Promise((resolve, reject) => {
      this.http.get('https://easy-mock.com/mock/5a1bcb8b9144e669fc6e94d6/getlazydata').subscribe(res => {
        // resolve( this.nzTreeService.generateInnerNodes(res['data'],this.nodeKeys))
        console.log(this.nzTreeService.generateInnerNodes(res['data'],this.nodeKeys));

        // 模拟返回的数据
        if(id == '2'){
          resolve([
            {
              pid:'2',
              id:'3',
              name:'设备控制-1',
              checked:true,
              'hasChildren':true

            },
            {
              pid:'2',
              id:'4',
              name:'设备控制-2',
              'hasChildren':true
            },
          ])
        }else if(id == '1'){
          resolve([
            {
              pid:'1',
              id:'5',
              name:'设备控制-1',
              'hasChildren':true
            }
          ])
        } else if(id == '4'){
          resolve([
            {
              pid:'4',
              id:'6',
              name:'设备控制-1',
              'hasChildren':true
            }
          ])
        }else{
          resolve([])
        }
      });
    });
  }

  onEvent(ev: any) {

  }
}

FAQs

Package last updated on 27 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc