如何使用angularjs

时间:2016-11-07 15:34:21

标签: javascript angularjs json

如何根据angularjs中的两个json数组对象过滤复选框,这里的键与comp1和comp2相同。如何将选中的这两个json对象推送到一个数组中。

var comp1=
[
  {
    "ID": "GROUP",
    "Name": "client ",
    "ListItemID": "GROUP",
    "ListItemUniqueId": "00000000-0000-0000-0000-000000000000",
    "isSelected": true
  },
  {
    "ID": "co1",
    "Name": "comp1",
    "ListItemID": "3",
    "ListItemUniqueId": "00000000-0000-0000-0000-000000000000",
    "isSelected": true
  }];
var comp2=[
  {
    "Access": null,
    "AuditFile": null,
    "CurrentItem": null,
    "DAPSortOrder": 1,
    "DocName": null,
    "DocTitle": null,
    "DocUrl": null,
    "EnableComponent": false,
    "Id": 1,
    "ImageUrl": null,
    "PeriodName": "Planning",
    "RelatesTo": co1,
    "created": null,
    "type": null
  }];

1 个答案:

答案 0 :(得分:0)

使用lodash union()和filter()函数。

https://lodash.com/docs/4.16.6#union

https://lodash.com/docs/4.16.6#filter

var newArray = filter( join(comp1, comp2), function (item) {
     return item.isSelected || item.PeriodName; // any condition you need
});