【发布时间】:2020-07-13 16:22:00
【问题描述】:
每次在我的数据库中创建一个新组时,我想使用 redux 触发一个计数器进入我的实时数据库中的 /categories/categoryId/groupsCount 节点。我构建了此代码以获取该特定 categoryId 的 groupsCount 值的当前计数,并尝试使用 +1 更新()。它没有用,我找不到任何其他方法来做这个简单的事情。
export const updateCategoryGroupCount = categoryId => {
return async dispatch => {
const currentCount = firebase
.database()
.ref('/categories/' + categoryId + '/groupsCount')
await firebase
.database()
.ref('/categories/' + categoryId)
.update({ groupsCount: currentCount + 1 })
.then(
dispatch({
type: UPDATE_CATEGORY_COUNT,
cid: categoryId,
total: currentCount + 1;
})
);
};
};
如何使用 firebase 查询从 /categories/id/groupCounts 获取值?
【问题讨论】:
标签: react-native firebase-realtime-database