douxuelv7755 2015-10-28 22:09
浏览 211

AngularJS将类添加到<td>,它由ngRepeat从数据库生成动态

I have problem with my table, because I have no idea how do it...

I have table in html which is generate dynamic by Angular with data from database and now I needed add some styles to td element. Style which I need add, I have get from database (background-color in rgb), but I don't know how?

Below is code which is generate by Angular in view:

<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>

Code which generate the table above:

<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>

And now I need get values from database of classes which start from 5th column to the last and to each add background style in rgb. I don't know where this whole procedure make... in the angular or php site. I will be very pleased if someone write me how should be step looks like... :)

EDIT 29.10.15: Print screens of database tables:

  1. Table where I get data to the table: enter image description here

  2. Table where I have classes: enter image description here

And the example code of one row, how I want to look like in the end:

<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>

The class is not required, I only need add the style inline.

  • 写回答

1条回答 默认 最新

  • dongqu7778 2015-10-28 22:25
    关注

    I am simplifying it assuming you have the color name saved in the DB, say you have a simple obj like this:

      $scope.items = [{
        "color":"red",
        "value":12
      },{
        "color":"green",
        "value":12
      },{
        "color":"blue",
        "value":12
      },{
        "color":"pink",
        "value":12
      }];
    

    Then in the HTML you can add inline style like this,

    <table>
          <tr ng-repeat="item in items" style="background:{{item.color}}"><td>{{item.value}}</td></tr>
    </table>
    

    Hope this solves your problem.

    Demo

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?