国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

angular-tree-component的使用詳解

2019-11-19 13:23:18
字體:
來源:轉載
供稿:網友

先上網址吧:https://github.com/500tech/angular-tree-component 這是牛逼哄哄的GitHub頁面, http://500tech.github.io/angular-tree-component/ 這就是官網啦。

大背景--首先我是在Angular4下面使用的。

1、install from npm :

npm install --save angular-tree-component

2、導入css

在styles.scss下面導入樣式:

@import '~angular-tree-component/dist/angular-tree-component.css';

3、import the module

app.module.ts

import { TreeModule } from 'angular-tree-component';@NgModule({ imports: [..., TreeModule], ...})export class AppModule { ...}

4、app.component.ts里面

nodes = [  {   id: 1,   name: 'root1',   children: [    { id: 2, name: 'child1' },    { id: 3, name: 'child2' }   ]  },  {   id: 4,   name: 'root2',   children: [    { id: 5, name: 'child2.1' },    {     id: 6,     name: 'child2.2',     children: [      { id: 7, name: 'subsub' }     ]    }   ]  } ]; options = {};

在 app.component.html里面

 <tree-root [nodes]="nodes" [options]="options"></tree-root>

到這里編譯出來就可以看到一棵樹啦

5、是不是感覺也不是很麻煩嫩,這棵樹是真的牛掰,為作者手動點贊。

在option里面可以配置一些參數:

顯示內容--displayfield:'name'(以顯示名稱為例)

id--idField: 'uuid'(如果沒有id,會隨機生成id,保證每個節點的唯一性)

是否展開節點:isExpandedField:'expanded'(默認是不展開的喲)

actionMapping:自定義事件,

 mouse: {     dblClick: (tree, node, $event) => {      if (node.hasChildren) TREE_ACTIONS.TOGGLE_EXPANDED(tree, node, $event);     }    }

支持按需加載:

getChildren: this.getChildren.bind(this),

6、events

<tree-root [nodes]="nodes"  (toggleExpanded)="onEvent($event)"  (activate)="onEvent($event)"  (focus)="onEvent($event)"  (blur)="onEvent($event)"> </tree-root> onEvent = ($event) => console.log($event);

有activate狀態就有deactivate狀態

7、在option里面添加:useCheckBox:true可以顯示checkBox。這時還可以有一個select事件,獲取的是子節點。那如果需要獲取父節點怎么處理呢,折騰了老半天之后,最終還是找到了方法。。。。

node.partialSelected 可以獲取到根節點喲。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 师宗县| 文昌市| 邢台县| 浦县| 阿克陶县| 五台县| 郧西县| 诸暨市| 阳曲县| 布拖县| 隆安县| 高雄县| 蛟河市| 招远市| 方城县| 荥经县| 清镇市| 平武县| 惠来县| 竹山县| 广昌县| 白城市| 铜梁县| 洱源县| 兰西县| 阿克苏市| 兴山县| 镇原县| 喀喇沁旗| 安宁市| 永顺县| 建瓯市| 武城县| 隆安县| 赤城县| 北流市| 尼木县| 红河县| 东辽县| 闵行区| 江西省|