AngularJS ng-repeat over multiple tr

Ben*_*Ben 5 javascript angularjs angularjs-ng-repeat

我正在尝试使用以下代码(数据来自API):

...
<tbody ng-repeat="verbinding in data.connection" style="border-bottom:2px solid black;">

    <tr>
        <td></td>
        <td></td>
        <td>{{verbinding.departure.time  * 1000 | date:'HH:mm'}}</td>
        <td>{{verbinding.departure.platform}}</td>
        <td><a href="/liveboard/{{verbinding.departure.stationinfo.id}}">{{verbinding.departure.station}}</td>
    </tr>

    <tr ng-if="verbinding.departure.vehicle == verbinding.arrival.vehicle">
        <td colspan = "5" style="text-align:center;">{{verbinding.departure.vehicle}}</td>
    </tr>
<span ng-if="verbinding.departure.vehicle != verbinding.arrival.vehicle" ng-repeat="via in verbinding.vias.via">
    <tr>
        <td>{{via.arrival.time * 1000 | date:'HH:mm'}}</td>
        <td>{{via.arrival.platform}}</td>
        <td>{{via.departure.time * 1000 | date:'HH:mm'}}</td>
        <td>{{via.departure.platform}}</td>
        <td><a href = "/liveboard/{{via.stationinfo.id}}">{{via.station}}</a></td>
    </tr>
    <tr>
        <td colspan = "5">{{via.vehicle.id}}</td>
    </tr>
</span>
...
Run Code Online (Sandbox Code Playgroud)

上面的代码不起作用.我使用它的原因span是因为我需要两个包含两个trs.以下工作:

...
<tr ng-if="verbinding.departure.vehicle != verbinding.arrival.vehicle" ng-repeat="via in verbinding.vias.via">
    <td>{{via.arrival.time * 1000 | date:'HH:mm'}}</td>
    <td>{{via.arrival.platform}}</td>
    <td>{{via.departure.time * 1000 | date:'HH:mm'}}</td>
    <td>{{via.departure.platform}}</td>
    <td><a href = "/liveboard/{{via.stationinfo.id}}">{{via.station}}</a></td>
</tr>
...
Run Code Online (Sandbox Code Playgroud)

但后来我只有一个tr,我需要两个.

Phi*_*ley 5

我想ng-repeat-startng-repeat-end可能是你在找什么.

来自文档:

ng-repeat-start指令与ng-repeat的作用相同,但会重复所有HTML代码(包括它定义的标记),包括放置ng-repeat-end的结束HTML标记.

也许是这样的......

<tbody ng-repeat="verbinding in data.connection" style="border-bottom:2px solid black;">

    <tr>
        <td></td>
        <td></td>
        <td>{{verbinding.departure.time  * 1000 | date:'HH:mm'}}</td>
        <td>{{verbinding.departure.platform}}</td>
        <td><a href="/liveboard/{{verbinding.departure.stationinfo.id}}">{{verbinding.departure.station}}</td>
    </tr>

    <tr ng-if="verbinding.departure.vehicle == verbinding.arrival.vehicle">
        <td colspan = "5" style="text-align:center;">{{verbinding.departure.vehicle}}</td>
    </tr>
    <tr ng-repeat-start="via in verbinding.vias.via">
        <td>{{via.arrival.time * 1000 | date:'HH:mm'}}</td>
        <td>{{via.arrival.platform}}</td>
        <td>{{via.departure.time * 1000 | date:'HH:mm'}}</td>
        <td>{{via.departure.platform}}</td>
        <td><a href = "/liveboard/{{via.stationinfo.id}}">{{via.station}}</a></td>
    </tr>
    <tr ng-repeat-end>
        <td colspan = "5">{{via.vehicle.id}}</td>
    </tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)