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

213
Views
Uso de variables en la ruta de Firebase con Vanilla JS al actualizar varias claves

Estoy tratando de actualizar varias rutas al mismo tiempo con mi base de datos de Firebase, pero cada ruta requiere variables para definir:

 const update_referral_path = "referrals/" + referral_code.trim() + "/" + current_user_id const new_referral_path = "profile/" + current_user_id + "/user_dict/profile/referral_code"

Estoy usando este código para actualizarlo, pero Firebase, como se esperaba, actualiza la base de datos con la cadena literal "update_referral_path" y "new_referral_path".

 admin.database().ref().update({ update_referral_path: current_time, new_referral_path: generated_referral_code }, error => { if (error) { console.log("updateReferral failed") return false } else { console.log("updateReferral succeeded") return true } })

He visto formas de usar variables en Angular con acentos graves y corchetes dobles, pero no estoy seguro de cómo puedo hacer esto en Vanilla JS y no puedo encontrar ningún ejemplo de personas que lo hagan. ¿Cuáles son mis opciones?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para usar el valor de la variable en una clave, use la notación [] :

 admin.database().ref().update({ [update_referral_path]: current_time, [new_referral_path]: generated_referral_code }, error => { ...

También puede crear un objeto JSON literal fuera de la llamada de update :

 let updates = {}; updates[update_referral_path] = current_time; updates[new_referral_path = generated_referral_code; admin.database().ref().update(updates);
about 4 years ago · Juan Pablo Isaza 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!