ng-repeat表示嵌套数组的角度

时间:2017-12-06 03:54:53

标签: javascript jquery angularjs

我在嵌套数组中获取数据。

我正在尝试以这种格式显示我的数据

Jan

01 Mon newyear
13 sat bhogi
14 sun pongal

Feb

14 tue Valentine's day

对于循环它有点困惑。

这就是我试过的

<table ng-repeat="list in holidayList" style="width:100%">
                            <thead>
                                <tr>
                                    @*<th>{{list.}}</th>*@
                                </tr>
                            </thead>
                            <tbody>
                                <tr ng-repeat="leave in list">
                                    <td width="14%">{{leave.date}}</td>
                                    <td width="20%">{{leave.monthCode}}</td>
                                    <td>{{leave.holiday_name}}</td>
                                </tr>
                            </tbody>
                        </table>

转换日期并不重要我为此编写了自定义过滤器和方法,因此我可以使用此过滤器和方法获得预期的日期格式:

app.filter('jsonDate', function () {
    return function (date) {
        return new Date(date.match(/\d+/)[0] * 1);
    }
})

$scope.dateFormat = function (date) {
        $scope.formattedDate = date.getFullYear() + "-" + (((date.getMonth() + 1).length) == 2 ? (date.getMonth() + 1) : ("0" + (date.getMonth() + 1))) + "-" + ((date.getDay().length) == 2 ? date.getDay() : ("0" + date.getDay()));
        return $scope.formattedDate
    }

当前输出:

/Date(1484397151447)/   1   pongal
/Date(1484310751447)/   1   Bhogi
/Date(1483273951447)/   1   new year
/Date(1494855933060)/   5   may day

任何人都可以告诉我应该如何循环以获得预期的格式。

1 个答案:

答案 0 :(得分:3)

您可以直接访问该对象:(我假设在每个数组项中定义了月份)

$scope.months = ["Jan", "February, "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

如果未定义月份,则使用javascript数组数月:

<td>{{months(list[0].monthCode - 1)}}</td>

然后在你的html:

list[0].monthCode

或仅{{1}}如果monthCode以1开头为0。