admin管理员组文章数量:1391804
I'm trying to use AngularJS to create a table of a list of events. But each event has a type, and events of different types have drastically different contents, and some types also generate more than one row.
In a perfect world, I'd do this:
<tbody>
<ng-repeat="event in events">
<ng-switch on="event.type">
<ng-switch-when="type1">
<tr>
...
</tr>
<tr>
...
</tr>
</ng-switch-when>
<ng-switch-when="type2">
<tr>
...
</tr>
</ng-switch-when>
...
</ng-switch>
</ng-repeat>
</tbody>
but this won't work because most browsers will discard or relocate the ng tags to enforce that the tbody only contains trs.
The only solution I've seen to related problem (How to use ng-repeat without an html element) is to have multiple tbody elements; I'd prefer not to do that, but even if I do this, giving the tbody the ng-repeat and ng-switch attributes, I still have the problem that I can't wrap multiple trs in a single ng-switch-when.
Is there a way to do this in AngularJS, or is this impossible?
I'm trying to use AngularJS to create a table of a list of events. But each event has a type, and events of different types have drastically different contents, and some types also generate more than one row.
In a perfect world, I'd do this:
<tbody>
<ng-repeat="event in events">
<ng-switch on="event.type">
<ng-switch-when="type1">
<tr>
...
</tr>
<tr>
...
</tr>
</ng-switch-when>
<ng-switch-when="type2">
<tr>
...
</tr>
</ng-switch-when>
...
</ng-switch>
</ng-repeat>
</tbody>
but this won't work because most browsers will discard or relocate the ng tags to enforce that the tbody only contains trs.
The only solution I've seen to related problem (How to use ng-repeat without an html element) is to have multiple tbody elements; I'd prefer not to do that, but even if I do this, giving the tbody the ng-repeat and ng-switch attributes, I still have the problem that I can't wrap multiple trs in a single ng-switch-when.
Is there a way to do this in AngularJS, or is this impossible?
Share Improve this question edited Jun 20, 2017 at 18:07 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jan 27, 2013 at 13:47 dplepagedplepage 931 silver badge4 bronze badges2 Answers
Reset to default 2I've run into this problem, best advice is don't use table:
just do a parent div id with * ammount of child div classes just like they are tr's and td's...
i haven't checked this in angular source but i'm assuming that the table elements aren't intertwined somehow, who knows..
Maybe the best option would be a directive that generates the appropriate markup based on your type1/type2?
You could probably also do it with ng-hide/ng-show, though that would generate extra unnecessary markup
本文标签: javascriptAngularjs ngrepeat and ngswitch on tr tagsStack Overflow
版权声明:本文标题:javascript - Angularjs: ng-repeat and ng-switch on tr tags - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744763660a2623900.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论