简体   繁体   中英

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.

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.

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.

I want to add following arrays that exist in code into JSON File.

I have all the arrays, I need to convert them into JSON file.

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

You can look into PouchDB. It's a javascript version of CouchDB. It's noSQL based (with documents). So you could do then is to fetch the data, store them into the (local) pouchDB instance. Then from that point on, you just do calls to pouchdb.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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