简体   繁体   中英

how can I toggle a boolean parameter in javascript?

I want to toggle a value called 'session' and then, update this value.

i've tried to do session=,session. but that didn't work, session is a parameter inside a object, this object are displayed on my nosql database. i'm using the realtime database from firebase.

however session:true and session:false works

更新方法中的会话

obs: English isn't my first lenguage, so sorry if I used wrong words.

Since you want to write a value to a path based on its existing value, you'll want to use a transaction .

Something like:

const userRef = ref(db, `/usuários/${fistKey}/session`);

runTransaction(userRef, (session) => {
  if (session) {
    return !session
  }
  return true; // 👈 default value
});

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