37 lines
703 B
TypeScript
37 lines
703 B
TypeScript
import { Component, OnInit,Input } from '@angular/core';
|
|||
|
|
|
||
|
|
@Component({
|
||
|
|
selector: 'app-sidebar-menu',
|
||
|
|
templateUrl: './sidebar-menu.component.html',
|
||
|
|
styleUrls: ['./sidebar-menu.component.scss']
|
||
|
|
})
|
||
|
|
export class SidebarMenuComponent implements OnInit {
|
||
|
|
//输入数据
|
||
|
|
@Input() data: Array<any>;
|
||
|
|
|
||
|
|
constructor() { }
|
||
|
|
|
||
|
|
ngOnInit() {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 判断是否有子节点
|
||
|
|
* @param item
|
||
|
|
*/
|
||
|
|
isLeaf(item: any) {
|
||
|
|
return !item.children || !item.children.length;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 菜单点击事件
|
||
|
|
* @param item
|
||
|
|
*/
|
||
|
|
itemClicked(item: any) {
|
||
|
|
if (!this.isLeaf(item)) {
|
||
|
|
item.isExpend = !item.isExpend;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|