映射 Firestore 保存字段名称
Map Firestore saving field name
你能帮帮我吗?我的代码有问题,因为我没有更新地图值,路径也发生了变化
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')
})
而不是
结果是
使用square brackets notation,如下,应该可以解决问题:
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' } })
正如您在评论中指出的那样,也有效。
你能帮帮我吗?我的代码有问题,因为我没有更新地图值,路径也发生了变化
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')
})
而不是
结果是
使用square brackets notation,如下,应该可以解决问题:
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' } })
正如您在评论中指出的那样,也有效。