无法遍历我的html中的数组

时间:2019-02-20 13:44:43

标签: angular typescript

我正在尝试为angular7创建一个面包屑组件,但是我无法使我的数组正确显示在HTML中,并且需要一些技巧,因为我无法在互联网上找到它。如果您愿意为我提供帮助,那么我仍然对角度不熟悉,并且想不出更好的方法来制作面包屑组件。

我的component.ts-

# Create a numpy array from the ID columns
a_ID = np.array(df['ID'])

# use the numpy unique method to get a unique array
# a = np.unique(np.array(df['ID']))
a = np.unique(a_ID)

# shuffle the unique array
np.random.seed(100)
np.random.shuffle(a)

# cut the shuffled array in half
X1 = a[0:25]

# create a boolean mask
mask = np.isin(a_ID, X1)

# set the index to the mask
df.index = mask
df.loc[True]

然后是我的HTML-

breadcrumbLists: Array <any> = [];
breadcrumburl: Array <any> = [];

constructor(private _router: Router) { }

ngOnInit() {
    this.listenrouting();
}

listenrouting(): void {
    let routerUrl: string, routerList: Array < any > ;
    let i;
    let done;
    this._router.events.subscribe((router: any) => {
        routerUrl = router.urlAfterRedirects;
        if (routerUrl && typeof routerUrl === 'string') {
            this.breadcrumbLists.length = 0;
            routerList = routerUrl.slice(1).split('/');
            this.breadcrumbLists = routerList;

            if (done != false) {

                this.breadcrumbLists.forEach(bread => {

                    if (i != null) {
                        this.breadcrumburl.push([{ name: bread }, { url: i + "/" + bread }])
                    } else {
                        this.breadcrumburl.push([{ name: bread }, { url: "/" + bread }])
                    }

                    i = "/" + bread

                });
            }

            console.log("url", this.breadcrumburl)
            console.log(this.breadcrumbLists)
            done = false;
        }
    });
}

1 个答案:

答案 0 :(得分:2)

  

如果我没记错,您想以-

的形式插入breadcrumburl数组
this.breadcrumburl.push({name: bread, url: i + "/" + bread});

当前,您创建了嵌套数组,并在breadcrumburl的所有嵌套数组中推送了2个元素