带有 ng-repeat 的数组数组 [英] Array of Arrays with ng-repeat

查看:30
本文介绍了带有 ng-repeat 的数组数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示按日期分组的列表,但该列表未排序,而且我不知道日期何时更改.就像我有这个 Json :

I am trying to show a list grouped by date but the list isn't sorted and I don't know when the date change. It's like I have this Json :

list = 
{name: first, date: 2014-05-21}, {
{name: second, date: 2014-05-20}, {
{name: third, date: 2014-05-21}

我想制作以下html:

I'd like to make the following html :

<li><h3>2014-05-21</h3>
 <ul>
  <li>first</li>
  <li>third</li>
 </ul>
</li>
<li><h3>2014-05-20</h3>
 <ul>
 <li>second</li>
 </ul>
</li>

你有什么想法吗?

我试图用两个 ng-repeat 制作一个数组数组,如下所示:

I tried to make an Array of arrays with two ng-repeat like this :

for (i in list){
 if ($scope.listToShow[list.date] == undefined) {
     $scope.listToShow[list.date] = newArray();
 }
 $scope.listToShow[list.date].push(list[i]); 
}

但我没有成功展示这一点.

But I don't success to show this.

推荐答案

检查 post,它准确地提到了你想要实现的目标.

Check the post, it exactly mention what you want to achieve.

http://www.bennadel.com/blog/2456-grouping-nested-ngrepeat-lists-in-angularjs.htm

您也可以使用 ng-repeat-start 和 ng-repeat-end(内置指令)来实现相同的效果.点击这里参考链接.

You can also use ng-repeat-start and ng-repeat-end (inbuilt directives) to achieve the same. Click here for Reference link.

这篇关于带有 ng-repeat 的数组数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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