gpt4 book ai didi

javascript - 使用带有 ng-repeat 的表内的 Angular js 动态更改 rowspan 值

转载 作者:行者123 更新时间:2023-11-30 16:39:46 25 4
gpt4 key购买 nike

我需要根据条件动态设置行跨度值。

我的数组:

 $scope.approvalitems = [
{ ReqId: '100' Date: '02-02-2015', AssociateID: '346248', },
{ ReqId: '101' Date: '02-02-2015', AssociateID: '346248', },
------------------------------------------
{ ReqId: '102' Date: '06-02-2015', AssociateID: '123456', },
{ ReqId: '103' Date: '06-02-2015', AssociateID: '123456', },
{ ReqId: '104' Date: '06-02-2015', AssociateID: '123456', },
-------------------------------------------
{ ReqId: '105', Date: '07-02-2015', AssociateID: '309645',},
{ ReqId: '106', Date: '07-02-2015', AssociateID: '309645',},
--------------------------------------------
{ ReqId: '107', Date: '08-02-2015', AssociateID: '346248',}
];

需要设置 DATE 和 AssociateID 值相同的行跨度值 =(count of items )。

我无法使用 ng-repeat 构建表格,尝试使用 group 但无法使用 groupBy 在 filter 中获取 Date 和 AssociateID 的唯一元素的计数。寻找解决此问题的方法。

需要这样。

Date       AssociateID      Time
-----------|----------|-----------------------
02-02-2015 |346248 | Click here for the time
-----------|----------|
02-02-2015 |346248 |
-----------|----------|----------------------
06-02-2015 |123456 | Click here for the time
-----------|----------|
06-02-2015 |123456 |
-----------|----------|
06-02-2015 |123456 |
-----------|----------|----------------------
07-02-2015 |309645 | Click here for the time
-----------|----------|
07-02-2015 |309645 |
-----------|----------|----------------------
08-02-2015 |346248 | Click here for the time

这是我的 Fiddle

那么如何实现这一点,我是否需要在绑定(bind)数组之前对其进行排序,如果是这样请指导我或者有没有更好的方法来实现这一点。我是 angular js 的新手。

最佳答案

在你的例子中,我会使用一个对象作为 map 来排序。

$scope.createObjectMap = function () {
var items = {};
angular.forEach($scope.approvalitems, function (value, key) {
if (!items['id' + value.AssociateID]) { // +id because properties shound not begin with numbers
items['id' + value.AssociateID] = new Array();
}
items['id' + value.AssociateID].push(value);
});
return items;
}

然后我会使用两个 ng-repeat,第一个遍历对象,第二个遍历值(数组)。看看我的fiddle .

如果有人有更好的解决方案请告诉我。

关于javascript - 使用带有 ng-repeat 的表内的 Angular js 动态更改 rowspan 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32178161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com