1
我有問題,我的表生成動態的,因爲我不知道該怎麼辦呢?AngularJS添加類這是ngRepeat從數據庫
我在HTML表是動態生成的角度與數據庫中的數據,現在我需要爲td元素添加一些樣式。我需要添加的樣式,我從數據庫(rgb中的背景顏色)獲得,但我不知道如何?
下面的代碼是由角鑑於產生:
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Lp.</th>
<th>image</th>
<th>Article name:</th>
<th>Colors in article:</th>
<th ng-repeat="y in [] | range:0:number">{{$index+1}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="pokayoke in pokayokes | filter : search track by $index">
<td>{{$index+1}}</td>
<td>obrazek</td>
<td ng-repeat="column in pokayoke" class="{{ column }}"><p>{{ column }}</p></td>
</tr>
</tbody>
</table>
現在我需要得到的類數據庫,從5日開始的值:
其產生上面的表格<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Lp.</th>
<th>image</th>
<th>Article name:</th>
<th>Colors in article:</th>
<th class="ng-binding ng-scope" ng-repeat="y in [] | range:0:number">1</th>
<th class="ng-binding ng-scope" ng-repeat="y in [] | range:0:number">2</th>
<th class="ng-binding ng-scope" ng-repeat="y in [] | range:0:number">3</th>
<th class="ng-binding ng-scope" ng-repeat="y in [] | range:0:number">4</th>
<th class="ng-binding ng-scope" ng-repeat="y in [] | range:0:number">5</th>
<th class="ng-binding ng-scope" ng-repeat="y in [] | range:0:number">6</th>
<th class="ng-binding ng-scope" ng-repeat="y in [] | range:0:number">7</th>
</tr>
</thead>
<tbody>
<tr class="ng-scope" ng-repeat="pokayoke in pokayokes | filter : search track by $index">
<td class="ng-binding">1</td>
<td>obrazek</td>
<td ng-repeat="column in pokayoke" class="11_14_1167"><p class="ng-binding">11_14_1167</p></td>
<td ng-repeat="column in pokayoke" class="C,M,Y,K,P286,P218"><p class="ng-binding">C,M,Y,K,P286,P218</p></td>
<td ng-repeat="column in pokayoke" class="x"><p class="ng-binding">x</p></td>
<td ng-repeat="column in pokayoke" class="x"><p class="ng-binding">x</p></td>
<td ng-repeat="column in pokayoke" class="C"><p class="ng-binding">C</p></td>
<td ng-repeat="column in pokayoke" class="C"><p class="ng-binding">C</p></td>
<td ng-repeat="column in pokayoke" class="x"><p class="ng-binding">x</p></td>
<td ng-repeat="column in pokayoke" class="x"><p class="ng-binding">x</p></td>
<td ng-repeat="column in pokayoke" class="x"><p class="ng-binding">x</p></td>
</tr>
<tr class="ng-scope" ng-repeat="pokayoke in pokayokes | filter : search track by $index">
<td class="ng-binding">2</td>
<td>obrazek</td>
<td ng-repeat="column in pokayoke" class="11_14_1171"><p class="ng-binding">11_14_1171</p></td>
<td ng-repeat="column in pokayoke" class="C,M,Y,K,P286,P7465"><p class="ng-binding">C,M,Y,K,P286,P7465</p></td>
<td ng-repeat="column in pokayoke" class="x"><p class="ng-binding">x</p></td>
<td ng-repeat="column in pokayoke" class="x"><p class="ng-binding">x</p></td>
<td ng-repeat="column in pokayoke" class="Y"><p class="ng-binding">Y</p></td>
<td ng-repeat="column in pokayoke" class="Y"><p class="ng-binding">Y</p></td>
<td ng-repeat="column in pokayoke" class="Y"><p class="ng-binding">Y</p></td>
<td ng-repeat="column in pokayoke" class="Y"><p class="ng-binding">Y</p></td>
<td ng-repeat="column in pokayoke" class="Y"><p class="ng-binding">Y</p></td>
</tr>
</tbody>
</table>
代碼列到最後,並在rgb中分別添加背景樣式。 我不知道整個過程在angular或php網站中的哪個位置。 我會很高興,如果有人寫我應該如何一步看起來像...... :)
編輯15年10月29日:數據庫表的 打印屏幕:
而且一行的示例代碼,我想怎麼樣到底如何:
<tr class="ng-scope" ng-repeat="pokayoke in pokayokes | filter : search track by $index">
<td class="ng-binding">1</td>
<td>obrazek</td>
<td ng-repeat="column in pokayoke" class="11_14_1167"><p class="ng-binding">11_14_1167</p></td>
<td ng-repeat="column in pokayoke" class="C,M,Y,K,P447,P218"><p class="ng-binding">C,M,Y,K,P447,P218</p></td>
<td ng-repeat="column in pokayoke" class="P447" style="background-color: rgb(39,46,32)"><p class="ng-binding">P447</p></td>
<td ng-repeat="column in pokayoke" class="P447" style="background-color: rgb(39,46,32)"><p class="ng-binding">P447</p></td>
<td ng-repeat="column in pokayoke" class="K" style="background-color: rgb(0,0,0)"><p class="ng-binding">K</p></td>
<td ng-repeat="column in pokayoke" class="K" style="background-color: rgb(0,0,0)"><p class="ng-binding">K</p></td>
<td ng-repeat="column in pokayoke" class="x" style="background-color: rgb(255,255,255)"><p class="ng-binding">x</p></td>
<td ng-repeat="column in pokayoke" class="x" style="background-color: rgb(255,255,255)"><p class="ng-binding">x</p></td>
<td ng-repeat="column in pokayoke" class="x" style="background-color: rgb(255,255,255)"><p class="ng-binding">x</p></td>
</tr>
該類不是必需的,我只需要添加樣式內聯。
但我已經在TD元素一個ngRepeat環,我可以在這同一個元素不止一個?一個循環爲不同的範圍? –
你能分享你的數據庫的結構和你想達到的最終結果嗎? – Nil
我編輯了問題,並添加了DB的結構和簡單的例子,我想它看起來像。 –