javascript - 请问在angular中,如下的数组循环效果该如何实现?
PHP中文网
PHP中文网 2017-04-11 09:02:06
0
2
226

如下:

蒙牛
3日 6日 8日 9日 30日
伊利
4日 5日
特仑苏
5日 10日 18日

这种形式应该如何循环?json数组怎么写呢?

PHP中文网
PHP中文网

认证0级讲师

Antworte allen(2)
Ty80

I will do like this.

html

<p ng-controller="MyCtrl">
    <ul>
        <li ng-repeat="p in data">
            <p>{{p.value}}</p>
            <ul>
                <li ng-repeat="c in p.children">{{c.value}}</li>
            </ul>
        </li>
    </ul>
</p>

script

$scope.data = [
    {
        key: 1,
        value: '蒙牛',
        children: [
            {
                key: 11,
                value: '3日',
            }
        ]
    },
    {
        key: 2,
        value: '伊利',
        children: [
            {
                key: 21,
                value: '4日',
            }
        ]
    }

];
Ty80

首先你这个东西如果存矩阵的话 [[{month:1月},{day:xx}],[{month:2月},{day:'2日'}]] 可以很方便的去除所有的日 或者所有的月 存对象的话更简单 {{month:1,childs:[1,2,3]},{month:2,childs:[1,2,3]}}

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!