0
我想使用ng-repeat
展示我的結果,但模板是有點特殊......自定義NG-重複AngularJs
它的工作原理使用EJS是這樣的:
<% var i = 0; %>
<% vehicles.forEach(function(vehicle, index){ %>
<% if (i === 0) {%>
<div class="line">
<% } %>
<div class="col-3">
<article>
<img src="/uploads/<%-vehicle.thumbnail%>" alt="<%-vehicle.title%>">
<h3><a href="/mes-vehicules/show/<%-vehicle.id%>"><%-vehicle.title%></a></h3>
<p><%-shortText(vehicle.description, 50)%></p>
<span><%-formatNumber(vehicle.priceTtc)%></span>
</article>
</div>
<% if(i === 3) { %>
</div>
<div class="space-10"></div>
<% i = -1; %>
<% } %>
<% i++; %>
<% }); %>
使用AngularJS我想知道該怎麼辦,我的代碼不工作...
<div class="line" ng-if="$index%3 == 0">
<div class="col-3">
<article>
<img src="/uploads/{{vehicle.thumbnail}}" alt="{{vehicle.title}}">
<h3><a href="/mes-vehicules/show/{{vehicle.id}}">{{vehicle.title}}</a></h3>
<p>{{vehicle.description | short}}</p>
<span>{{vehicle.priceTtc | formatNumber}}</span>
</article>
</div>
</div ng-if="$index%3 == 0">
你嘗試過什麼到目前爲止? – Aron
我想你會想要這樣的東西:'ng-class =「{line:$ index%3 = 0}」'而不是'ng-if' – devqon
一種選擇是將控制器中的車輛陣列 –