简体   繁体   English

如何将Angular服务响应添加到JSON文件

[英]How to add Angular service response into JSON file

I'm dealing with a huge dataSet using Angular5 service, so I want to call the backend API once and want to save the result into JSON. 我正在使用Angular5服务处理庞大的dataSet,因此我想一次调用后端API,并将结果保存到JSON。

I fetch the response and then store into several arrays according to my need,I'm looking how to add those arrays into JSON file. 我获取响应,然后根据需要将其存储到多个数组中,我正在寻找如何将这些数组添加到JSON文件中。

getAllConcepts(){
   let allOrderUUID="b3dac224-fdea-11e4-b248-005056820298";
 this.allOrderableService.getAllOrderableConcepts(allOrderUUID).subscribe(allOrders=>{
    let allOrderable=allOrders;
    allOrderable.setMembers[0].setMembers.forEach(labSample=>{
      this.labSamples.push(labSample);
    });
    allOrderable.setMembers[1].setMembers.forEach(radOrder=>{
      this.radiologyOrder.push(radOrder);
    });
    this.separatePanelAndLabTestInlabSamples(this.labSamples);
    this.separatePanelAndOrderInRadiologyLab(this.radiologyOrder);    
  });
}

separatePanelAndLabTestInlabSamples(labSample:any){
  console.log("@receivedLabSample",labSample);
  if(labSample.length>0)
  {
    labSample[0].setMembers.forEach(response=>{
      if(response.conceptClass.uuid==="33a6291c-8a92-11e4-977f-0800271c1b75")
        {
          this.labSamplesTest.push(response);
        }
     if(response.conceptClass.uuid==="8d492026-c2cc-11de-8d13-0010c6dffd0f")
        {
          this.labSamplesPanel.push(response);
        }
  });
  console.log("LabTest",this.labSamplesTest);
  console.log("LabPanel",this.labSamplesPanel);
  }
}

I'm able to receive the response,after getting the reponse I'm storing them into severals arrays,I'm confuse how I can add these array into JSON file for future use.The basic aim is to reduce the call to server. 我能够接收到响应,得到响应后,将它们存储到几个数组中,我混淆了如何将这些数组添加到JSON文件中以备将来使用。基本目的是减少对服务器的调用。

I want to add following arrays that exist in code into JSON File. 我想将代码中存在的以下数组添加到JSON File中。

I have all the arrays, I need to convert them into JSON file. 我拥有所有数组,我需要将它们转换为JSON文件。

据我所知,您无法保存对文件的响应,因为它需要服务器端访问。

You can look into PouchDB. 您可以查看PouchDB。 It's a javascript version of CouchDB. 这是CouchDB的javascript版本。 It's noSQL based (with documents). 它基于noSQL(带有文档)。 So you could do then is to fetch the data, store them into the (local) pouchDB instance. 因此,您可以做的是获取数据,并将其存储到(本地)pouchDB实例中。 Then from that point on, you just do calls to pouchdb. 从那时起,您只需调用pouchdb。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM