角2如何通过多维数组迭代? [英] Angular 2 how to iterate through multi-dimensional arrays?

查看:136
本文介绍了角2如何通过多维数组迭代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑#2

EDIT#2

不幸的是,我还没有纳入这些建议任何一个没有成功。这是晚了,所以我前往去睡觉,但我会尝试更新的明天。

Unfortunately, I haven't had any success incorporating either one of these suggestions. It's late, so I'm heading off to bed, but I'll try to update tomorrow.

我已经学会了如何使用* ngFor命令,但它看起来像它只能简单数组的作品。这里的code我试图遍历。

I've learned how to use the *ngFor command, but it looks like it only works with simple arrays. Here's the code I'm trying to iterate through.

import {Lesson} from './lesson';

export var LESSONS: Lesson[] = [
{
    "idL": 1,
    "subject": 'Chapter One',
    "points": [
                'picture story', 'spelling test', 'words'
            ]
},
{
    "idL": 2,
    "subject": 'Words',
    "points": [
            'words', 'bacon', 'proliferation'
    ]
}
]

所以我试图访问被称为点的第二个数组。我不认为它的​​格式不正确的,但我一直无法弄清楚如何访问它。

So I am trying to access that second array called "points". I don't think it's improperly formatted, but I haven't been able to figure out how to access it.

我也读到angularJs的的foreach命令,但Angular2的文档没有表现出这样的命令可用。

I did read about angularJs's foreach command, but Angular2's documentation does not show such a command is available.

有何建议?

推荐答案

试试这个 -

<table>
<template ngFor #lesson [ngForOf]="LESSONS" #i="index">
  <template ngFor #point [ngForOf]="lesson.points" #j="index">
  <tr>{{point}}</tr>
  </template>
</template>

工作例如<大骨节病> 工作Plunker。

Working example Working Plunker.

这篇关于角2如何通过多维数组迭代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆