javascript - 使用 ng-repeat 创建动态列和行

标签 javascript html angularjs

我正在使用 angularjs,我想用 ng-repeat 创建动态行,但无法实现。看到我的代码后我会清除。这是我的代码和 jsfiddle :-

td.controllers.js

function TodoCtrl($scope) {
 $scope.products = [{
            name: 'Abc'
        }, {
            name: 'Bil'
        }, {
            name: 'Smart'
        }];
}

td.html

<div ng-app>
  <div ng-controller="TodoCtrl">
   <table class="table">
    <thead>
                            <tr>
                                <th rowspan="2">Month</th>
                                <th ng-repeat="product in products" colspan="2">{{product.name}}</th>
                            </tr>
                            <tr>
                                <th>A</th> //I want to dynamic it
                                <th>B</th> //
                            </tr>
                        </thead>
   </table>

  </div>
</div>

我想要的输出是:-

-----------------------------
Month | Abc | Bil | Smart
      | A|B | A|B | A|B
----------------------------

最佳答案

<div ng-app>
  <div ng-controller="TodoCtrl">
   <table class="table">
    <thead>
                            <tr>
                                <th rowspan="2">Month</th>
                                <th ng-repeat="product in products">{{product.name}}</th>
                            </tr>
                            <tr>
                                <th></th> <!--I want to dynamic it-->
                                <th ng-repeat="product in products">A|B</th> 
                            </tr>
                        </thead>
   </table>

  </div>
</div>

试试这个代码 这里表头和表数据都是动态创建的。

如果您遇到任何问题,请告诉我

关于javascript - 使用 ng-repeat 创建动态列和行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43580453/

相关文章:

javascript - 如何将日期时间转换为 mm/dd/yyyy 格式

html - 文本不会保留在网站上的父级中,即使被证明可以在多个平台上工作

jQuery 数据表大小调整问题

ios - 如何在 ionic framework latest beta 14 上同时使用选项卡和滑动菜单?

html - md-next-button 不适用于 Angular Material

javascript - 使用 PHP V8JS 渲染 javascript 时出现问题

javascript - 我如何确定在第一次加载时是否在 jQuery 中单击了某些内容?

javascript - 在react中setState后状态值没有被修改

html - <hr> 每三个 <div> 下面

javascript - 范围变量应用问题期间的 Angular 快速单击