我的桌子有问题,因为我不知道怎么做......
我在html中有一个表格,它由Angular生成动态数据库中的数据,现在我需要为td元素添加一些样式。我需要添加的样式,我从数据库(rgb中的背景颜色)得到,但我不知道怎么样?
下面是Angular在视图中生成的代码:
<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>
生成上表的代码:
<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列到最后一列的类数据库中获取值,并在rgb中添加每个背景样式。 我不知道整个程序在角落或php网站中的位置。 如果有人写信告诉我应该如何步骤,我会很高兴... :)
编辑29.10.15: 打印数据库表的屏幕:
一行的示例代码,我最终想要的样子:
<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>
该类不是必需的,我只需要添加样式内联。
答案 0 :(得分:0)
我正在简化它,假设你在数据库中保存了颜色名称,假设你有一个像这样的简单obj:
$scope.items = [{
"color":"red",
"value":12
},{
"color":"green",
"value":12
},{
"color":"blue",
"value":12
},{
"color":"pink",
"value":12
}];
然后在HTML中你可以像这样添加内联样式,
<table>
<tr ng-repeat="item in items" style="background:{{item.color}}"><td>{{item.value}}</td></tr>
</table>
希望这能解决你的问题。