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 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答