Verwenden von ng-repeat mit Tabellenzeilen

Ich versuche zum einfügen von Daten aus einem Modell in ein template aber ich möchte hinzufügen, um eine neue Zeile in der Tabelle, nachdem alle 7 Wiederholungen. Mit strign-basierte Vorlagen, die ich tun könnte es ganz einfach mit der iteration index-und modulo-aber ich kann nicht ganz herausfinden, wie Sie dies tun, indem Sie eckige DOM Vorlagen.

Hier die HTML-Ausgabe:

<div ng-controller="MyCtrl">
  <table cellspacing="0" cellpadding="0">
   <colgroup span="7"></colgroup>

   <tbody>
     <tr class="days">
       <th scope="col" title="Monday">Mon</th>
       <th scope="col" title="Tuesday">Tue</th>
       <th scope="col" title="Wednesday">Wed</th>
       <th scope="col" title="Thursday">Thu</th>
       <th scope="col" title="Friday">Fri</th>
       <th scope="col" title="Saturday">Sat</th>
       <th scope="col" title="Sunday">Sun</th>
     </tr>
     <tr>
         <td ng-repeat="date in dates">
             {{ date }}
             <!-- After seven iterations a new `<tr>` should be aded -->
        </td>
     </tr>
 </tbody>
 </table>
</div>

Sowie javascript, mit dem Sie so etwas wie:

myApp = this.angular.module('myApp', []);

var monthDays = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1516, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];

myApp.controller('MyCtrl', function($scope) {
  return $scope.dates = monthDays;
});​

Sie können den code in JSFiddle hier: http://jsfiddle.net/3zhbB/2/

InformationsquelleAutor der Frage DaveJ | 2012-09-20

Schreibe einen Kommentar