2017-05-26 5 views
0

私は列見出しとして週の日数を持つテーブルを持つ列でNGリピートで表を移入します私は各列に配列の値を代入したいと思います。代わりに、これを代わりに列に使用するにはどうすればよいですか?AngularJSは

echo "<tbody>"; 
echo "<tr id='schedule_row' ng-repeat='tv_show in tv_shows | orderBy:sortType:sortReverse'>"; 
echo "<td>{{tv_show.show_name}}</td>"; // Show Names column 
echo "</tr>"; 
echo "</tbody>"; 

私はそれをこのように試みたが、それはちょうど同じ列にこれを追加しました:

echo "<tbody>"; 
echo "<tr id='mondays' ng-repeat='monday in mondays'>"; 
echo "<td>{{monday}}</td>"; 
echo "</tr>"; 
echo "<tr id='tuesdays' ng-repeat='tuesday in tuesdays'>"; 
echo "<td>{{tuesday}}</td>"; 
echo "</tr>"; 
echo "<tr id='wednesdays' ng-repeat='wednesday in wednesdays'>"; 
echo "<td>{{wednesday}}</td>"; 
echo "</tr>"; 
echo "<tr id='thursdays' ng-repeat='thursday in thursdays'>"; 
echo "<td>{{thursday}}</td>"; 
echo "</tr>"; 
echo "<tr id='fridays' ng-repeat='friday in fridays'>"; 
echo "<td>{{friday}}</td>"; 
echo "</tr>"; 
echo "<tr id='saturdays' ng-repeat='saturday in saturdays'>"; 
echo "<td>{{saturday}}</td>"; 
echo "</tr>"; 
echo "<tr id='sundays' ng-repeat='sunday in sundays'>"; 
echo "<td>{{sunday}}</td>"; 
echo "</tr>"; 
echo "</tbody>"; 

修正作成:

echo "<tbody>"; 
echo "<tr>"; 
echo "<td>"; 
echo "<li class='li_class' ng-repeat='monday in mondays'>{{monday}}</li>"; 
echo "</td>"; 
echo "<td>"; 
echo "<li class='li_class' ng-repeat='tuesday in tuesdays'>{{tuesday}}</li>"; 
echo "</td>"; 
echo "<td>"; 
echo "<li class='li_class' ng-repeat='wednesday in wednesdays'>{{wednesday}}</li>"; 
echo "</td>"; 
echo "<td>"; 
echo "<li class='li_class' ng-repeat='thursday in thursdays'>{{thursday}}</li>"; 
echo "</td>"; 
echo "<td>"; 
echo "<li class='li_class' ng-repeat='friday in fridays'>{{friday}}</li>"; 
echo "</td>"; 
echo "<td>"; 
echo "<li class='li_class' ng-repeat='saturday in saturdays'>{{saturday}}</li>"; 
echo "</td>"; 
echo "<td>"; 
echo "<li class='li_class' ng-repeat='sunday in sundays'>{{sunday}}</li>"; 
echo "</td>"; 
echo "</tr>"; 
echo "</tbody>"; 

答えて

0

はあなたがよ、同期日を保つために一度だけ繰り返すが、リスト内のあなたの位置を追跡したい(基本的に各行は1週間である)。これを実現するために、あなたはこれが実際に機能するためにtrack by $indexdocumentation

<tbody> 
    <tr id="week{{$index}}" ng-repeat="monday in mondays track by $index"> 
    <td id="monday{{$index}}">{{mondays[$index]}}</td> 
    <td id="tuesday{{$index}}">{{tuesdays[$index]}}</td> 
    <td id="wednesday{{$index}}">{{wednesdays[$index]}}</td> 
    <td id="thursday{{$index}}">{{thursdays[$index]}}</td> 
    <td id="friday{{$index}}">{{fridays[$index]}}</td> 
    <td id="saturday{{$index}}">{{saturdays[$index]}}</td> 
    <td id="sunday{{$index}}">{{sundays[$index]}}</td> 
    </tr> 
</tbody> 

を含むことができ、毎日の配列は同じ長さにする必要がありますし、順序が正しいことが必要になります。よりクリーンな実装では、データを週単位で格納することがあります。その後、

var weeks = [{monday:"mondayValue", tuesday:"tuesdayValue", ... sunday:"sundayValue"}]; 

<tr id="week{{$index}}" ng-repeat="week in weeks track by $index"> 
    <td id="monday{{$index}}>{{week.monday}}</td> 
... 
</tr>