如何使firestoreConnect指向React-Redux-Firebase中的嵌套集合?

Mow*_*zer 7 firebase reactjs react-redux google-cloud-firestore react-redux-firebase

下一行直接指向firestoreConnect标有的我的收藏projects

 { collection: 'projects' }
Run Code Online (Sandbox Code Playgroud)

当项目集合直接位于根目录下时,它将起作用:

root/
  projects/
Run Code Online (Sandbox Code Playgroud)

但是,如果项目集合被本身位于另一个集合中的文档所引用,例如:

root/
  users/
    alice/
      projects/
Run Code Online (Sandbox Code Playgroud)

我怎么点firestoreConnectprojects集合?

该文档对此未作说明。

链接到视频
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)
Run Code Online (Sandbox Code Playgroud)

编辑:尝试失败

从我在这里的评论中可以得出的结论来看,答案可能是:

firestoreConnect([
  { 
    collection : 'users',
    doc        : 'alice',
    collection : 'projects',
  }
])
Run Code Online (Sandbox Code Playgroud)

但是那个尝试失败了。

Sco*_*ott 8

可以通过将多个收集/文档设置传递给subcollections参数来完成,如下所示:

firestoreConnect(() => [
  {
    collection: 'states',
    doc: 'CA',
    subcollections: [
      { collection: 'cities', doc: 'SF' },
      { collection: 'zips' }
    ]
  }
])
Run Code Online (Sandbox Code Playgroud)

在react-redux-firebase文档firestoreConnect部分中对此进行了说明(因为它是特定于React的HOC)。可传递给查询的选项记录在redux-firestore的README文件中

如果您要进行嵌套的子集合,则可能要使用这些v1.*.*版本,因为子集合会以redux状态存储在侧面顶级集合中。请注意,新版本具有不同的API,如v1.0.0路线图中所述

披露:我是redux-firestore的作者

  • +1。我的 $.02:鼓励人们在 SO 上发布他们的问题。通过提供示例,它可以很好地扩充您的文档。有了足够多的例子,全面的文档就变得不那么重要了。Gitter 有利于建立社区。如果人们在这里发布他们的问题,那么知识库会更加持久,并且也更容易搜索和查找。这也将帮助新用户发现您的图书馆。构建该库的工作非常出色! (2认同)