Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
RxJS Loop httpGet result luego haga httpPut y httpPost en diferentes escenarios

Tengo un formulario de interfaz de usuario para actualizar o agregar texto de traducción.

Necesitaría escribir la declaración rxjs para cumplir con lo siguiente:

  1. Inicie httpGet en la base de datos para obtener traducciones de varios idiomas

  2. Recorre la lista de traducciones.

  3. Si los campos de mi interfaz de usuario coinciden con las traducciones de httpGet, necesitaría hacer una serie de httpPut para actualizarlos en la base de datos. Ejemplo: Completé la traducción al español en la interfaz de usuario, si mi httpGet arroja resultados que incluyen español, necesitaría HttpPut para actualizar el registro en español en la base de datos.

  4. Si mis campos de IU no existen en las traducciones de httpGet, necesitaría hacer una serie de httpPost para actualizarlos en la base de datos. Ejemplo: Completé la traducción al chino en la interfaz de usuario, si mi httpGet no devuelve ningún resultado en chino, necesitaría httpPost para agregar un registro chino en la base de datos.

Escribí la primera parte, pero entiendo que rxjs no es secuencial y no puede escribir una suscripción en otra suscripción, no puedo escribirlo de esta manera.

p/s: Mi httpGet me devuelve x, en el que tiene la estructura de x.dataCount y x.dataSet. x.dataCount es el número de objetos de traducción. x.dataSet es una matriz de objetos de traducción.

¿Cómo escribo la declaración rxjs para esto? ¿Cualquier pista?

 this.GetTranslations(group).subscribe(x => { x.dataSet.forEach(translation => { switch (translation.Language) { case chineseCode: if (chineseInUI){ chineseExist = true; let newChinese = { "Id": translation.Id, "Language": translation.Language, "PhraseKey": translation.PhraseKey, "PhraseValue": chineseInUI, } this.webApiService.httpPut$(this.resourceApiService.getURL('translationmanagerURL') + translation.Id, newChinese).subscribe(); } break; case spanishCode: if (spanishInUI){ let newSpanish = { "Id": translation.Id, "Language": translation.Language, "PhraseKey": translation.PhraseKey, "PhraseValue": spanishInUI } this.webApiService.httpPut$(this.resourceApiService.getURL('translationmanagerURL') + translation.Id, newSpanish).subscribe(); } break; } }); });
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Puedes hacerlo así usando operadores

  • mergeMap para crear una matriz de observables
  • mergeAll para obtener los valores de los observables internos en la suscripción
 this.GetTranslations(group) .pipe( mergeMap((x) => { return x.dataSet.map((translation) => { switch (translation.Language) { case chineseCode: if (chineseInUI) { chineseExist = true; let newChinese = { Id: translation.Id, Language: translation.Language, PhraseKey: translation.PhraseKey, PhraseValue: chineseInUI, }; return this.webApiService.httpPut$( this.resourceApiService.getURL('translationmanagerURL') + translation.Id, newChinese ); } break; case spanishCode: if (spanishInUI) { let newSpanish = { Id: translation.Id, Language: translation.Language, PhraseKey: translation.PhraseKey, PhraseValue: spanishInUI, }; return this.webApiService.httpPut$( this.resourceApiService.getURL('translationmanagerURL') + translation.Id, newSpanish ); } break; } return EMPTY; }); }), mergeAll() ) .subscribe((response) => { console.log('response', response); });

Ejemplo de trabajo (con datos simulados)

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!