reactjs - 如何将 firestoreConnect 指向 React-Redux-Firebase 中的嵌套集合?
问题描述
下面的行指向firestoreConnect
我的收藏,标签为projects
。
{ collection: 'projects' }
当项目集合立即位于根目录下时,它可以工作,如下所示:
root/
projects/
但是,如果项目集合被本身位于另一个集合中的文档引用,例如,像这样:
root/
users/
alice/
projects/
我如何指向firestoreConnect
集合projects
?
import React, { Component } from 'react'
import ProjectList from '../projects/ProjectList'
import Notifications from './Notifications'
import { connect } from 'react-redux'
import { firestoreConnect } from 'react-redux-firebase'
import { compose } from 'redux'
import { Redirect } from 'react-router-dom'
class Dashboard extends Component {...}
const mapStateToProps = (state) => {
// console.log(state);
return {
projects: state.firestore.ordered.projects,
auth: state.firebase.auth,
}
}
export default compose(
connect(mapStateToProps),
firestoreConnect([
{ collection: 'projects' }, // <-- Question is about this line
])
)(Dashboard)
编辑:不成功的尝试
从我可以从这里的评论中拼凑出来的答案似乎是:
firestoreConnect([
{
collection : 'users',
doc : 'alice',
collection : 'projects',
}
])
但这种尝试失败了。
解决方案
可以通过将多个集合/文档设置传递给subcollections
参数来完成,如下所示:
firestoreConnect(() => [
{
collection: 'states',
doc: 'CA',
subcollections: [
{ collection: 'cities', doc: 'SF' },
{ collection: 'zips' }
]
}
])
这在 react-redux-firebase 文档的 firestoreConnect 部分中有说明(因为它是特定于反应的 HOC)。可以传递给查询的选项记录在 redux-firestore 的 README 中。
如果你正在做嵌套的子集合,你可能会想要使用这些v1.*.*
版本,因为子集合以 redux 状态存储在侧顶级集合中。请注意,新版本具有不同的 API,如 v1.0.0 路线图中所述。
披露:我是 redux-firestore 的作者
推荐阅读
- java - 如何使用 selenium 处理移动 OTP
- excel - VBA 相交行和列
- xamarin.forms - 如何在 Xamarin 表单的集合视图上添加 Click 事件
- ios - cocos2d JS WebGL 渲染在 iOS 14 公测版中不起作用
- css - 引导重新排序列以最小化给定行的大小
- python - model.predict(dataset) 给我“*: 'int' and 'NoneType' 的不支持的操作数类型”错误
- javascript - 在Angular中以反应形式测试输入元素时如何触发焦点和模糊事件?
- sql - Oracle:选择查询以通过将其格式从 varchar 更改为日期来过滤日期列
- javascript - 安装后如何触发vue的自定义指令
- java - Selenium 不接受我的 xpath 表达式