我有一个父容器,如下所示:
const HomeContainer = Relay.createContainer(HomeClass, {
initialVariables: {
first: 66,
userIdAndCookie: {
id: "",
cookie: ""
},
filterBy: {subTypes: ["Event","Social Media Photography"]}
},
fragments: {
allUsersFragment: ($params) => Relay.QL`
fragment on AllUsers {
${UserBoxList.getFragment('allUsersFragment', $params)}
}
`,
}
}以及一个嵌套容器,如下所示:
export default Relay.createContainer(UserBoxList, {
initialVariables: {
first: 600,
filterBy: null
},
fragments: {
allUsersFragment: ({$first, $filterBy}) => Relay.QL`
fragment on AllUsers {
allUsersField(first: $first, filterBy: $filterBy) {
edges {
node {
id,
name,
surname,
businessName,
rating,
supplierType,
locationNames,
locationZips
}
}
}
}
`
}
});HomeContainer正确地将参数传递给UserBoxList,当我查看网络选项卡时,我正确地接收了使用正确参数完成的查询中的所有数据。然而,当我这样做时:
const users = this.props.allUsersFragment.allUsersField.edges.map(user => {
if(user.node.supplierType === this.props.selectedSupplierType) {
return (
<UserBox
usernode={user.node}
key={user.node.id}
showCreateTaskRequestBox={this.props.showCreateTaskRequestBox}
/>
)
}
});在我的UserBoxList中,allUsersField是未定义的。当我看this.props.allUsersFragment的时候,我看到了这个:
Object {__dataID__: "client:-222288344603", __status__: 4}但没有数据!尽管我可以在网络选项卡中看到数据:
{data: {,…}}
data
:
{,…}
allUsersQuery
:
{_allUsersField1YSY3b: {edges: [{,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…},…],…}}
_allUsersField1YSY3b
:
{edges: [{,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…},…],…}
edges
:
[{,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…},…]
pageInfo
:
{hasNextPage: true, hasPreviousPage: false}我的问题是,我是不是遗漏了一些明显的东西?还是这是个窃听器?
编辑
如果我删除从Home -> UserBoxList传递的变量,并且只在UserBoxList中使用initialVariables,它就能正常工作。
在初始呈现时,UserBoxList中继变量不是我从家乡传递的变量,而是来自UserBoxList容器中的initialVariables的变量,但实际执行的唯一查询是使用来自Home容器的正确参数
EDIT2
显然,github在同样的问题上也存在一个问题:
发布于 2016-04-30 16:57:51
约瑟夫·萨沃纳( Joseph Savona )给我的答案是:
确保在道具中传递任何重写的变量,因此<Child customerId={this.props.relay.variables.customerId} ... />。
https://stackoverflow.com/questions/36944787
复制相似问题