Angular.js:基于对象中项目的重复次数

时间:2013-01-16 20:50:20

标签: angularjs

页面上基本上有两个ng-repeats,共享一个Object。我想只在符合type数据的情况下重复项目。

模拟对象

        $scope.events = [
            {
                date: "1/16/13",
                time: "11:30",
                type: "First",
                restaurant: "Quiznos",
                location: "Echo",
                cuisine: "American",
                link: "http://google.com/event?id=239292"
            },
            {
                date: "1/16/13",
                time: "1:30",
                type: "Second",
                restaurant: "Snarfs",
                location: "5th Floor",
                cuisine: "American",
                link: "http://google.com"
            }
];

标记

        <tr ng-repeat="event in events.type " onClick="window.open('{{event.link}}','_blank');">
                <td>{{event.time}}</td>
                <td>{{event.restaurant}}</td>                   
                <td>{{event.location}}</td>
                <td>{{event.cuisine}}</td>
        </tr>

所以我想要两次ng重复。 on for type = First,one for type = Second

ng-repeat="event in events.type = 'First'"

这样的东西

1 个答案:

答案 0 :(得分:7)

您正在寻找the filter filter ...

<tr ng-repeat="event in events | filter:{ type: 'First'}"/>