Angularjs 当旧标签与新标签不匹配时,将行添加到表中
我正在寻找一些关于angularjs代码的帮助 当Angularjs 当旧标签与新标签不匹配时,将行添加到表中,angularjs,Angularjs,我正在寻找一些关于angularjs代码的帮助 当{{notification.label}从一个值更改为另一个值时(表的内容来自数据库),我想添加一个新行。然而,我不能让它工作,主要是因为我不知道如何做到这一点。最好我甚至关闭表并创建一个新表,但因为循环在TR中,我猜这是不可能的 寻找一些方向,也许是一个例子。已经试验过If指令,但无法将旧标签与新标签进行比较 <div id=postModule data-ng-app="postModule" data-ng-controller="
{{notification.label}
从一个值更改为另一个值时(表的内容来自数据库),我想添加一个新行。然而,我不能让它工作,主要是因为我不知道如何做到这一点。最好我甚至关闭表并创建一个新表,但因为循环在TR中,我猜这是不可能的
寻找一些方向,也许是一个例子。已经试验过If指令,但无法将旧标签与新标签进行比较
<div id=postModule data-ng-app="postModule" data-ng-controller="PostController" data-ng-init="init()"
<form novalidate name="notificationForm">
<table class="table table-bordered table-hover table-striped">
<tr data-ng-repeat="notification in post.notification | orderBy : 'label'">
<td>
{{notification.label}}
</td>
<td>
{{notification.vendor}}
</td>
<td>
{{notification.product}}
</td>
<td>
{{notification.version}}
</td>
<td>
{{notification.cve}}
</td>
<td>
{{notification.cvsscore}}"
</td>
</tr>
</table>
</form>
</div>
我想看看这样的东西(桌子)
如果那是两张分开的桌子,那就更好了
notification.label || notification.vendor || notification.product
expensive || Samsung || Galaxy
expensive || Apple || iPhone
notification.label || notification.vendor || notification.product
budget || Huawai || X
budget || Huawai || Y
您可以使用
groupBy
来实现这一点
//代码在这里
angular.module('app',['angular.filter']))
.controller('MainController',函数($scope){
$scope.notifications=[{
标签:“昂贵”,
供应商:“三星”
}, {
标签:“昂贵”,
供应商:“索尼”
}, {
标签:“昂贵”,
卖主:“moto”
}, {
标签:“预算”,
供应商:“iphone”
}, {
标签:“预算”,
供应商:“x”
}];
});代码>
.custom{
页边距底部:0px!重要;
}
.custom>tbody>tr>th
{
宽度:50%;
浮动:左;
边界:没有!重要;
}
角度过滤器-groupBy和sum示例
通知标签
通知供应商
{{notification.label}
{{notification.vendor}}
notification.label是如何更改的?它的数据来自一个数据库,该数据库是在Ajax代码的帮助下加载的。我们如何知道它是否已从数据库更改?因此,基本上,默认情况下页面上有一些值,有人会在数据库中更改label的值,然后您需要在原始问题中添加新行?添加数据库布局。目前它是按标签排序的,但目前对预算进行了昂贵的更改,我想在前端添加一行table@Vivz谢谢效果很好。需要注意的一点是,您需要角度过滤器,因为默认情况下,angularjs不支持groupBy。
notification.label || notification.vendor || notification.product
expensive || Samsung || Galaxy
expensive || Apple || iPhone
notification.label || notification.vendor || notification.product
budget || Huawai || X
budget || Huawai || Y
notification.label || notification.vendor || notification.product
expensive || Samsung || Galaxy
expensive || Apple || iPhone
notification.label || notification.vendor || notification.product
budget || Huawai || X
budget || Huawai || Y