Карта Firestore, сохраняющая название поля - PullRequest
0 голосов
/ 13 апреля 2020

ты можешь мне помочь? У меня проблема с моим кодом, потому что вместо обновления значения карты путь также меняется

    const userId = firebase.auth().currentUser.uid;

    const availableRecord = firebase.firestore().collection('orders').doc(this.state.OrderId);
    availableRecord.update({
      stores: {  userId: 'On the way'}
  }).then(( res) => {
     console.log('Product is set into AVAILABLE')

    })

Вместо this result

результат равен enter image description here

1 Ответ

1 голос
/ 13 апреля 2020

Использование обозначения в квадратных скобках , как следует, должно помочь:

    const userId = firebase.auth().currentUser.uid;

    const availableRecord = firebase.firestore().collection('orders').doc(this.state.OrderId);

    const stores = {};
    stores[userId] = 'On the way';

    availableRecord.update({ stores }).then(() => {
       console.log('Product is set into AVAILABLE');
    });

Выполнение

  availableRecord
    .update({ stores: { [userId]: 'On the way' } })

также работает, как вы отметил в вашем комментарии.

...