欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Angluar+zorro實(shí)現(xiàn)無限級(jí)菜單

 更新時(shí)間:2022年03月25日 15:57:42   作者:武中奇  
這篇文章主要為大家詳細(xì)介紹了Angluar+zorro實(shí)現(xiàn)無限級(jí)菜單,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

關(guān)于Angular + zorro 實(shí)現(xiàn)無限級(jí)菜單,供大家參考,具體內(nèi)容如下

該文章為思路+代碼,為通用式前端無限級(jí)菜單。

首先通過后臺(tái)接收到的數(shù)據(jù)是這樣的

"table":[
? ? {
? ? "id": 1017.0,
? ? "menuName": "用戶管理",
? ? ? ? "child":[{
? ? ? ? ? ? "id": 23.0,
? ? ? ? ? ? "menuName": "用戶維護(hù)",
? ? ? ? ? ? "child": [{
? ? ? ? ? ? ? ? ? ? "id": 24.0,
? ? ? ? ? ? ?? ??? ?"menuName": "用戶查看",
? ? ? ? ? ? ? ? ? ? "child":[{
? ? ? ? ? ? ? ? ? ??? ??? ? ? ?"id": 25.0,
? ? ? ? ? ? ?? ??? ??? ??? ?"menuName": "用戶增加",
? ? ? ? ? ? ? ? ? ??? ??? ??? ?"child":[]
? ? ? ? ? ? ? ? ? ? }]
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? "id": 25.0,
? ? ? ? ? ? ?? ??? ?"menuName": "用戶增加",
? ? ? ? ? ? ? ? ? ? "child":[]
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ]
? ? ? ? }]
? ? },
? ? {
? ? "id": 1018.0,
? ? "menuName": "微信管理",
? ? "child":[] ? ?
? ? }
]

實(shí)現(xiàn)步驟如下:

1. uc-home.component.html

<!--
strHtml : 需要展示的數(shù)據(jù)
innerhtmlpipe :添加管道,讓數(shù)據(jù)擁有樣式
-->
<div [innerHTML]="strHtml | innerhtmlpipe"></div>

2. 因?yàn)橥ㄟ^在component.ts進(jìn)行數(shù)據(jù)拼接傳到頁面樣式不會(huì)顯示,所以使用Angular提供的管道讓其有樣式。

2.1新建一個(gè)管道

命令: ng g pipe innerhtmlpipePipe

2.2.

innerhtmlpipePipe.pipe.ts

import { Pipe, PipeTransform } from '@angular/core';
import {DomSanitizer} from '@angular/platform-browser';

@Pipe({
? name: 'innerhtmlpipe'
})
export class InnerhtmlpipePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
? transform(value): any {
? ? ? //樣式
? ? return this.sanitizer.bypassSecurityTrustHtml(value);
? }

}

3.uc-home.component.ts

import {Component, OnInit, ChangeDetectorRef} from '@angular/core';
import {Router, NavigationEnd} from '@angular/router';


@Component({
? selector: 'nb-uc-home',
? templateUrl: './uc-home.component.html',
? styleUrls: ['./uc-home.component.scss'],
? animations: [slideInAnimation]
})

export class UcHomeComponent implements OnInit {
? ? //定義一個(gè) strHtml
? ? public ?strHtml;
? ? //數(shù)據(jù)
? ? public menuArray = [];
? ??
? ? ?constructor(
? ? ??? ?private homeService: HomeService,
? ? ? ? ?private ref: ChangeDetectorRef
? ? ?) {}
? ? ngOnInit() {
? ? ? ? ? ?//從后臺(tái)接口獲取數(shù)據(jù),賦值給menuArray
? ?this.homeService.getMenu().subscribe(data => {
? ? ? ?//賦值數(shù)據(jù)
? ? ? ? this.menuArray = data.table;
? ? ? ? ? ?//初始化頁面
? ? ? ? this.strHtml = '';
? ? ? ?//遍歷每一個(gè)數(shù)據(jù)
? for (let i = 0; i < this.menuArray.length; i++) {
? ? ??
? ? ? ? const arr = this.menuArray[i];
//開始拼接頁面
? ? ? ? this.strHtml += '<ul nz-menu [nzMode]="\'inline\'" style="height:auto" >';
? ? ? ?? ?this.strHtml +='<li nz-submenu>';
? ? ? ? this.strHtml += '<div menuEvent title>';
? ? ? ? this.strHtml +='<span type="laptop">' + arr.menuName + '</span>' ;
? ? ? ?? ?this.strHtml +='</div>';
? ? ? //遍歷到孩子的時(shí)候調(diào)用一個(gè)方法,循環(huán)把孩子全部遍歷出來
? ? ? ? this.strHtml += this.creatHtml(arr.child);
? ? ? ? this.strHtml += '</li>';
? ? ? ?? ?this.strHtml += '</ul>';
? ? ? }
? ? ? ? //數(shù)據(jù)加載完畢之后重新渲染頁面
? ? ? ? ? ? ?this.ref.markForCheck();
? ? ? }); ? ? ?
? ? }

? ??
?creatHtml(cArr): any {
? ? let str = '';
? ? for (let i = 0; i < cArr.length; i++) {
? ? ? str += '<ul>';
? ? ? str += '<li nz-menu-item';
? ? ? str += '<div menuEvent>';
? ? ? str += '<span>' + cArr[i].menuName +'</span>';
? ? ? str += '</div>';
? ? ? str += '</li>';
? ? ? str += '</ul>';
? ? }
? ? ?//是否存在子集
? ? if (cArr.child) {
? ? ? str += this.creatHtml(cArr.child);
? ? }
? ? this.ref.markForCheck();
? ? return str;
? }
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 在 Angular 中使用懶加載路由的方法

    在 Angular 中使用懶加載路由的方法

    延遲加載是一種限制加載用戶當(dāng)前需要的模塊的方法,這可以提高應(yīng)用程序的性能并減小初始捆綁包大小,在本文中,您學(xué)習(xí)了如何在 Angular 應(yīng)用程序中使用惰性加載路由,本文分步驟講解的非常詳細(xì),感興趣的朋友一起看看吧
    2024-02-02
  • AngularJS輕松實(shí)現(xiàn)雙擊排序的功能

    AngularJS輕松實(shí)現(xiàn)雙擊排序的功能

    網(wǎng)上已經(jīng)有AngularJS比較多的相關(guān)教程了,那么這篇文章我們一起來看一個(gè)AngularJS雙擊排序的例子,對(duì)大家日常開發(fā)很有幫助的,有需要的可以參考借鑒。
    2016-08-08
  • 詳解Angular 開發(fā)環(huán)境搭建

    詳解Angular 開發(fā)環(huán)境搭建

    Angular 是一款開源 JavaScript 框架,使開發(fā)和測試變得更加容易,這篇文章主要介紹了詳解Angular 開發(fā)環(huán)境搭建,需要的朋友可以參考下
    2017-06-06
  • 詳解AngularJS如何實(shí)現(xiàn)跨域請(qǐng)求

    詳解AngularJS如何實(shí)現(xiàn)跨域請(qǐng)求

    跨域請(qǐng)求一直是網(wǎng)頁編程中的一個(gè)難題,在過去,絕大多數(shù)人都傾向于使用JSONP來解決這一問題。不過現(xiàn)在,我們可以考慮一下W3C中一項(xiàng)新的特性——CORS(Cross-Origin Resource Sharing)了。
    2016-08-08
  • AngularJS的臟檢查深入分析

    AngularJS的臟檢查深入分析

    這篇文章主要介紹了AngularJS的臟檢查深入分析,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-04-04
  • Angularjs中數(shù)據(jù)綁定的實(shí)例詳解

    Angularjs中數(shù)據(jù)綁定的實(shí)例詳解

    這篇文章主要介紹了Angularjs中數(shù)據(jù)綁定的實(shí)例詳解的相關(guān)資料,這里提供簡單實(shí)例,大家可以參考下,希望通過本文可以掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-08-08
  • angularJS深拷貝詳解

    angularJS深拷貝詳解

    本篇文章主要介紹了angularJS深拷貝,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-03-03
  • 詳解Angular4 路由設(shè)置相關(guān)

    詳解Angular4 路由設(shè)置相關(guān)

    本篇文章主要介紹了詳解Angular4 路由設(shè)置相關(guān),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • angularjs數(shù)組判斷是否含有某個(gè)元素的實(shí)例

    angularjs數(shù)組判斷是否含有某個(gè)元素的實(shí)例

    下面小編就為大家分享一篇angularjs數(shù)組判斷是否含有某個(gè)元素的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • AngularJS的Filter的示例詳解

    AngularJS的Filter的示例詳解

    本文通過示例給大家詳解angularjs 的filter知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2017-03-03

最新評(píng)論