用ng-repeat循环出一个不规则的表格遇到了问题
来源:互联网 发布:2017新开淘宝卖什么好 编辑:程序博客网 时间:2024/06/06 16:47
https://segmentfault.com/q/1010000002900072
我有一条json如下:
[{"teacher":"Tom","student":[{"name":"stuA","project":"projectA"},{"name":"stuB","project":"projectB"}]},{"teacher":"Jerry","student":[{"name":"stuC","project":"projectC"},{"name":"stuD","project":"projectD"},{"name":"stuE","project":"projectE"}]},{"teacher":"Lee","student":[{"name":"stuF","project":"projectF"}]}]
现在我想把这些数据通过ng-repeat渲染进一个表格中,预想图如下:
但是遇到了很多的困难,这估计是遇过的最麻烦的ng-repeat的实践.附上这个表格的html代码,方便大家清楚地看到这个表格的结构:
但是遇到了很多的困难,这估计是遇过的最麻烦的ng-repeat的实践.附上这个表格的html代码,方便大家清楚地看到这个表格的结构:
<tr style="height:40px" > <td rowspan="2" style="text-align:center;background:#FFD4D4;font-weight:bold;">Tom</td> <td style="text-align:center;font-size:15px;font-weight:bold;">stuA</td> <td style="text-align:left;padding-left:100px;font-size:15px;font-weight:bold;">projectA</td> </tr> <tr style="height:40px;"> <td style="text-align:center;font-size:15px;font-weight:bold;">stuB</td> <td style="text-align:left;padding-left:100px;font-size:15px;font-weight:bold;">projectB</td> </tr><tr style="height:40px"> <td rowspan="3" style="text-align:center;background:#FFD4D4;font-weight:bold;">Jerry</td> <td style="text-align:center;font-size:15px;font-weight:bold;">stuC</td> <td style="text-align:left;padding-left:100px;font-size:15px;font-weight:bold;">projectC</td></tr><tr style="height:40px;"> <td style="text-align:center;font-size:15px;font-weight:bold;">stuD</td> <td style="text-align:left;padding-left:100px;font-size:15px;font-weight:bold;">projectD</td></tr><tr style="height:40px;"> <td rowspan="1" style="text-align:center;background:#FFD4D4;font-weight:bold;">Lin</td> <td style="text-align:center;font-size:15px;font-weight:bold;">stuE</td> <td style="text-align:left;padding-left:100px;font-size:15px;font-weight:bold;">projectE</td></tr>
这个循环的问题在于,teacher是独占几行的,而且还得嵌套循环。所以请求大神发动一下脑筋帮我想想这个ng-repeat具体该如何实现
解决方案:
<table class="table table-bordered"> <thead> <tr> <th>teacher</th> <th>student</th> <th>project</th> </tr> </thead> <tbody ng-repeat="teacher in vm.teachers"> <tr ng-repeat="student in teacher.student track by $index"> <td ng-if="$index ==0" rowspan={{teacher.student.length}}>{{teacher.name}}</td> <td> <span ng-bind="student.name"></span> </td> <td><span ng-bind="student.project"></span> </td> </tr> </tbody></table>
阅读全文
0 0
- 用ng-repeat循环出一个不规则的表格遇到了问题
- 用ng-repeat循环出一个不规则的表格
- AngularJS ng-repeat表格嵌套循环
- 解决angularjs 使用 ng-repeat 循环输出时html元素无法解析的问题
- AngularJS中ng-repeat对象的问题
- 关于AngularJs的ng-repeat问题
- Angular用ng-repeat生成表单并绑定ng-click时的一个细节
- 使用ng-repeat循环数据重新渲染问题
- 如何知道ng-repeat循环的dom已经渲染完成
- 使用了ng-repeat 后的样式显示 ng-class 、ng-hide ng-show ng-if ng-style
- ng-repeat的使用
- AngularJs ng-repeat性能问题
- ng-repeat重复元素问题
- angularJS12-ng-repeat 指令用在一个对象数组上
- AngularJs ng-repeat 必须注意的性能问题
- 解决AngularJS中ng-repeat不更新视图的问题
- AngularJs ng-repeat 必须注意的性能问题
- angularJS11-ng-repeat 来循环数组
- 人工智能(AI)期末复习
- LeetCode 455. Assign Cookies(数组,排序)
- 新概念4-6
- 决定从头开始分析u-boot-1.1.4源码(三)
- 2134-->数据结构实验之栈四:括号匹配
- 用ng-repeat循环出一个不规则的表格遇到了问题
- Hi3518E V200R001C05SPC050使用笔记
- Javascript关键字,条件语句,循环语句,函数
- python中列表 字典 元祖 enumerate()函数
- U-Boot启动过程完全分析
- Hystrix 工作流程解析
- Activity的四种启动模式
- java通过jedis使用redis,以及部分api介绍
- 【初探】快速排序