如何为三层深的元素使用过滤器

时间:2019-02-11 14:25:27

标签: angular filter

我有一个从服务呼叫返回的结构:

var office = [
  {
    "Name": "office 1",
    "address": [
      {
        "address1": "addres line 1",
        "LocationOptions": [
          {
            "WheelChairAccessible": "Yes",
        "OpenToPublic": "Open"
         }
        ]
      },
    {
      "address1": "addres line 1",
      "LocationOptions": [
        {
          "WheelChairAccessible": "No",
      "OpenToPublic": "Closed"
        }
      ]
     },
    ]
   },
     "Name": "office 2",
     "address": [
       {
         "address1": "addres line 1",
         "LocationOptions": [
       {
              "WheelChairAccessible": "No",
          "OpenToPublic": "Closed"
           }
     ]
        }
     ]
   }
];

我一直在尝试应用过滤器,以便可以在服务呼叫中以所需的格式恢复数据,但是无法使过滤器工作到多个级别。

我已经尝试了以下方法,以将所需信息分解为要查找的数据:

this.fileteraddress = this.ds.serviceCall(detailParameters)
      .pipe( 
        filter(res => 
          res.Address.map( res => 
            res2.LocationOptions.filter( res3 =>
              res3.OpenToPublic != "Open")
          ) 
        )
      .subscribe (res =>
        this.fileteraddress = res
      );

我也尝试过使用地图功能,但是无法正确应用滤镜。

我希望过滤器能够正常工作,因此我可以像这样返回数据:

var Open Offices = [
  {
    "Name": "office 1",
    "address": [
      {
        "address1": "addres line 1",
    "LocationOptions": [
           {
        "WheelChairAccessible": "Yes",
            "OpenToPublic": "Open"
       }
     ]
      }
    ]
  }    
];

1 个答案:

答案 0 :(得分:0)

您将以数组的形式获得响应。

    function CopyDataToNewFile() {

// How Many Columns over to copy
var columsCopyCount = 4; // A=1 B=2 C=3 ....

// What Column to Monitor
var columnsToMonitor = 3; // A=1 B=2 C=3 ....MONITORS In or Out

//TARGET SPREAD SHEETS
var HallPass = "Hall_Pass"
var CheckOut = "Out";
var CheckIn = "In";

//SOURCE SPREAD SHEET
var ss = SpreadsheetApp.openById('1B93n7wQ8rosmcaqlpgD9FoL1KWfbXALrror7t6r5K2M'); //Need ID from Form response sheet
var sourceSpreadSheetSheetID = ss.getSheetByName(HallPass);
var sourceSpreadSheetSheetID1 = ss.getSheetByName(CheckOut);
var sourceSpreadSheetSheetID2 = ss.getSheetByName(CheckIn);

var data = sourceSpreadSheetSheetID.getRange(2, 1,sourceSpreadSheetSheetID.getLastRow()-1, sourceSpreadSheetSheetID.getLastColumn()).getValues();

var Out = [];
var In = [];


for (var i = 0; i < data.length; i++) {

    var rValue = data[i][2];

    if (rValue == CheckOut) {
        Out.push(data[i]);
    } else if (rValue == CheckIn) {
        In.push(data[i]);

    }
}

if(Out.length > 0){
  sourceSpreadSheetSheetID1.getRange(sourceSpreadSheetSheetID1.getLastRow() + 1, 1, Out.length, Out[0].length).setValues(Out);
  sourceSpreadSheetSheetID.deleteRows(2,sourceSpreadSheetSheetID.getLastRow() - 1);
}

if(In.length > 0){
   sourceSpreadSheetSheetID2.getRange(sourceSpreadSheetSheetID2.getLastRow() + 1, 1, In.length, In[0].length).setValues(In);
   sourceSpreadSheetSheetID.deleteRows(2,sourceSpreadSheetSheetID.getLastRow() -1);
}}

如果您想尝试一下,这里是堆叠闪电战。 https://stackblitz.com/edit/angular-xecicg