html - 带有指令的AngularJS表行
问题描述
我正在尝试使用 angularjs 指令来渲染表格。我想要的输出是在 tbody 中有子 tr 和 th
<table>
<thead>
<tr>COL 1</tr>
<tr>COL 2</tr>
<th col="2">Title 1</th>
</thead>
<tbody ng-repeat="i in [1, 2, 3, 4]">
<tr>
<td>i.name</td>
<td>i.value</td>
</tr>
<tr></tr>
</tbody>
</table>
对于上表,我有一些子内容应该出现在任何 tr 下方。子内容具有 th 和 tr(第 th 内容应仅在其 tr 元素列表上方出现一次)。那些孩子 tr 可以再次生孩子。你明白了。
这是我尝试和观察到的。
我在 tr 元素上使用了自定义属性指令。
app.directive('customDirective', ['$compile', function($compile){
return {
restrict: 'A',
scope: {
content: '='
},
link: function(scope, element) {
// SOME LOGIC TO DECIDE IF THE TEMPLATE NEEDS TO BE RENDERED TO STOP MAX EXECUTION ERROR
var template = '<tbody>
<th col="2">Title 1.1</th>
<tr custom-directive>
<td>content.name</td>
<td></td>
</tr>
</tbody>';
element.parent().after($compile(template)(scope));
}
}
}]);
第一个问题:我必须第二次使用 tbody 标签才能使用 CSS 属性;我不确定为什么它不保留表的属性。
第二个问题:第二级子级(标题 1.1.1)根本没有渲染,也没有控制台错误。
解决方案
推荐阅读
- sql - 如何自动从 SQL 中的查询中获取 excel 文件?(例如,在一个目标中每 1 小时。)
- apache-spark - 如何解决这个用例,以任何方式使用、数组、结构、爆炸和结构数据?
- python - 如何在熊猫中将多行不同大小的行折叠成一行?
- html - 使用 jquery 搜索多个列表并显示搜索项
- c++ - Linux 等价于 Process.Start()
- mysql - 如何在mysql比较秒
- axapta - 如果字段值大于 0,则启用禁用菜单项按钮的 AX 代码
- c# - 使用 C# 的 3D Unity 游戏的运动脚本不起作用
- azure-application-insights - 如何通过 Javascript SDK 在 Microsoft Application Insights 中禁用“RemoteDependencyData”?
- android-studio - 是否有在 Android Studio 4 上初始化项目的功能?